A simple Python Web application deployment Nginx+uwsgi

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.