Nginx Series-7. Configuring Nginx using UWSGI support web.py framework

Source: Internet
Author: User
Tags nginx reverse proxy

Nginx Series-7. Configuring Nginx with UWSGI support web.py Framework Catalog-Nginx Series

Nginx Series -1.linux Installation Nginx
Nginx Series-2. Configuring the Lnmp (Linux, Nginx, MySQL, PHP) architecture
Nginx Series-3. Configuring Nginx Virtual Host
Nginx Series -4.nginx log configuration and log cutting
Nginx Series-5. Configure the Nginx anti-theft chain
Nginx Series-6. Configuring Nginx HTTPS
Nginx Series-7. Configuring Nginx using UWSGI support web.py Framework
Nginx Series-8. Configuration nginx+apache for dynamic and static separation
Nginx Series-9. Configuring NFS for static and dynamic separation of Nginx
Nginx Series-10. Using Nginx to build forward proxy service
Nginx Series-11. Configuring Nginx Reverse proxy and load balancing

Experimental Environment
A minimized CentOS 7.3 virtual machine
ip:192.168.204.133

First, the installation of the basic environment
  1. Install the basic Environment

    yum install -y epel*yum install -y nginx python-pip python-devel pcre-devel libxml2-devel gcc vim tree psmisc

    Pip is required to gcc install Uwsgi
    UWSGI process Management is required psmisc

  2. Installing the Python library file

    pip install web.pypip install uwsgi
  3. Create a Web site root directory

    mkdir /var/wwwrootcd /var/wwwroot
  4. Write a test page
    Create and edit /var/wwwroot/main.py

    #!/usr/bin/python#coding=utf-8import web    urls = (‘/(.*)‘, ‘hello‘)app = web.application(urls, globals())class hello:        def GET(self, name):    if not name:        name = ‘World‘    return ‘Hello, ‘ + name + ‘!‘if __name__ == "__main__":app.run()# 使用nginx作web服务时,注意添加下面这句话application = app.wsgifunc()

  5. To main.py Add executable permissions

    chmod +x /var/wwwroot/main.py
  6. Shutting down the firewall
    setenforce 0systemctl stop firewalldsystemctl disable firewalld
Second, the configuration Nginx and Uwsgi
  1. Modify Nginx configuration file
    Modify server the root root directory for the Web site
    locationthe configuration in the modification is as follows

    location / {    include uwsgi_params;    uwsgi_pass 127.0.0.1:9090; #此套接字为uwsgi监听的地址和端口    uwsgi_param UWSGI_CHDIR $document_root; #此处代表网站根目录    uwsgi_param UWSGI_SCRIPT main; #此处为应用的入口文件}

  2. Start nginx

    systemctl start nginxnetstat -anpt | grep nginx
  3. Configuration uwsgi
    Create and edit /ect/uwsgi.ini

    [uwsgi]socket = 127.0.0.1:9090workers = 4

  4. Start uwsgi
    Open a new terminal! new terminal ! NEW terminal!!! Execute the following command

    uwsgi --ini /etc/uwsgi.ini 2>&1 &exit

  5. Go back to the previous terminal to see uwsgi if it starts properly

    netstat -antp | grep -E "9090|uwsgi"

  6. Stop uwsgi
    killall uwsginetstat -antp | grep -E "9090|uwsgi"

Third, testing
    1. On host access
Four, one-click Deployment scripts
#!/bin/bash# shut down firewall setenforce 0systemctl stop firewalldsystemctl disable firewalld# Install the foundation package Yum install-y Epel*yum Install -y nginx python-pip python-devel pcre-devel libxml2-devel gcc vim tree psmisc# install python module pip install web.pypip install UW sgi# establish a Web site root directory mkdir/var/wwwrootcd/var/wwwroot# build test page echo-e "#!/usr/bin/python#coding=utf-8import Web urls = ('/(.            *) ', ' hello ') app = Web.application (URLs, Globals ()) class Hello:def GET (self, name): If not name: name = ' World ' return ' Hello, ' + name + '! ' if __name__ = = \ "__main__\": App.run () # When using Nginx as a Web service, be careful to add the following sentence application = App.wsgifunc () ">/var/wwwroot/main.py # Add executable permissions chmod +x/var/wwwroot/main.py# Modify nginx config file Nginx_conf_path=/etc/nginx/nginx.confsed-i ' s/^[^#].*root.*/ro OT \/var\/wwwroot;/g ' ${nginx_conf_path}sed-i "a \ include Uwsgi_params;" ${nginx_conf_path}sed-i            "A \ Uwsgi_pass 127.0.0.1:9090;" ${nginx_conf_path}sed-i "Uwsgi_param uwsgi_chdir \ $document _root; "${nginx_conf_path}sed-i" a \ uwsgi_param uwsgi_script main; "${ng inx_conf_path}# start Nginxsystemctl start NGINXNETSTAT-ANPT | grep nginx# configuration Uwsgiecho-e "[uwsgi]socket = 127.0.0.1:9090workers = 4" >/etc/uwsgi.ini# start uwsgiecho-e "Uwsgi starting ... "Uwsgi--ini/etc/uwsgi.ini 2>&1 &

Nginx Series-7. Configuring Nginx using UWSGI support web.py framework

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.