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
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
Installing the Python library file
pip install web.pypip install uwsgi
Create a Web site root directory
mkdir /var/wwwrootcd /var/wwwroot
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()
To main.py
Add executable permissions
chmod +x /var/wwwroot/main.py
- Shutting down the firewall
setenforce 0systemctl stop firewalldsystemctl disable firewalld
Second, the configuration Nginx and Uwsgi
Modify Nginx configuration file
Modify server
the root
root directory for the Web site
location
the 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; #此处为应用的入口文件}
Start nginx
systemctl start nginxnetstat -anpt | grep nginx
Configuration uwsgi
Create and edit /ect/uwsgi.ini
[uwsgi]socket = 127.0.0.1:9090workers = 4
Start uwsgi
Open a new terminal! new terminal ! NEW terminal!!! Execute the following command
uwsgi --ini /etc/uwsgi.ini 2>&1 &exit
Go back to the previous terminal to see uwsgi
if it starts properly
netstat -antp | grep -E "9090|uwsgi"
- Stop
uwsgi
killall uwsginetstat -antp | grep -E "9090|uwsgi"
Third, testing
- 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