A simple Python web application to deploy Nginx + Uwsgi
1. Environment configuration
(1) Required environment
Operating system: Mac Os,linux
Python, Web.py,uwsgi,uwsgitop,nginx
(2) Steps
Installing python,web.py
Installing UWSGI:PIP Install Uwsgi
Installing UWSGITOP:PIP Install Uwsgitop (detects UWSGI running status)
Installation Nginx:pip Install Nginx
2. Writing the Python web App app.py
(1) Code
#Coding:utf-8ImportWeburls= ('/','Index') App=web.application (URLs, Globals ())classIndex:defGET (self): greeting="Hello World" returngreetingapplication=App.wsgifunc ()if __name__="__main__": Pass
2) Note
application = App.wsgifunc () is essential, it acts as handler for WSGI or UWSGI operations, UWSGI does not run code in __MAIN__
3. Configure Uwsgi
1) Write App.ini file
=/users/cityking/workspace/django/uwsgi.sockwsgi-file ==/users/cityking/workspace/django/ django_env/= True
Attention
Ensure that the file directory where the app.py is located
The socket is guaranteed to be the same as the Uwsgi_pass in the Nginx configuration,/users/cityking/workspace/django/uwsgi/is the current directory
Home is the directory where the environment is running
2) Start Uwsgi
Uwsgi.ini
4. Configure Nginx
1) Copy the system configuration file nginx.conf file
Cp/usr/local/etc/nginx.conf my_nginx.conf
ln my_nginx.conf/usr/local/etc/nginx/my_nginx.conf
Modify My_nginx.conf
server { listen 8080; server_name localhost; / { include uwsgi_params; Uwsgi_pass Unix:/users/cityking/workspace/django/uwsgi/uwsgi.sock } }
Listen is the listening port, which is the port accessed by the browser
Uwsig_pass is the socket path in the UWSGI configuration
5. Accessing in the browser
Accessing http://localhost:8080 in the browser
Show Hello World on Web page deployment success
A simple Python web application to deploy Nginx + Uwsgi