A simple Python web application to deploy Nginx + Uwsgi

Source: Internet
Author: User

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

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.