A simple Python Web application deployment Nginx+uwsgi
1. Environment configuration
1) Required Environment
Operating system Mac OS
python3.6,web.py 0.40, Uwsgi 2.0.15, Uwsgitop 0.10, Nginx 1.10.3
2) steps
Installation python3.6-slightly
Installing web.py
Easy_install web.py (recommended)
Pip Install web.py
If the error may also need to install Utils db
Pip Install Utils
PIP Install db
Installing UWSGI
Pip Install Uwsgi
Installing Uwsgitop
Uwsgitop function: Monitor UWSGI operation status
Pip Install Uwsgitop
Installing 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 necessary, it acts as a wsgi or Uwsgi Handler,uwsgi does not run code in __MAIN__
3. Configure Uwsgi
1) Write App.ini file
=/users/cityking/workspace/django/uwsgi/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 App.ini
4. Configure Nginx
1) Modify the/usr/local/etc/nginx/nginx.conf file
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
Uwsgi_pass is the socket path in the UWSGI configuration
2) Start Nginx
Just type in the command, Nginx.
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 deployment Nginx+uwsgi