uWSGI+Nginx安裝、配置


1、關閉SELINUX:

[root@PYTHON27 /]# vim /etc/selinux/config
將SELINUX=enforcing修改為SELINUX=disabled

2、關閉防火牆:

[root@PYTHON27 /]# service iptables stop
[root@PYTHON27 /]# chkconfig iptables off

3、安裝EPEL源:

[root@PYTHON27 /]# yum -y install epel-release
[root@PYTHON27 /]# yum clean all
[root@PYTHON27 /]# yum makecache

4、安裝系統工具:

[root@PYTHON27 /]# yum -y install vim wget telnet

5、安裝編譯支持包:

[root@PYTHON27 /]# yum -y install gcc gcc-c++ automake autoconf

6、安裝Nginx支持包:

[root@PYTHON27 /]# yum -y install zlib zlib-devel pcre pcre-devel openssl openssl-devel

7、安裝uwsgi及組件:

[root@PYTHON27 /]# yum -y install uwsgi uwsgi-devel uwsgi-plugin-python

8、查看uwsgi版本:

[root@PYTHON27 /]# uwsgi --version
2.0.14

9、啟動uwsgi項目:

[root@PYTHON27 /]# uwsgi --ini /usr/local/src/python-test/python-test.ini

10、解壓nginx安裝包:

[root@PYTHON27 /]# tar -xzvf /usr/local/src/nginx-1.10.1.tar.gz -C /usr/local/src/

11、編譯、安裝:

[root@PYTHON27 /]# cd /usr/local/src/nginx-1.10.1
[root@PYTHON27 nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
[root@PYTHON27 nginx-1.10.1]# make -j 2
[root@PYTHON27 nginx-1.10.1]# make install

12、修改Nginx配置文件:

[root@PYTHON27 /]# vim /usr/local/nginx/conf/nginx.conf
將下邊內容:
        location / {
            root   html;
            index  index.html index.htm;
        }
        
替換為:

        location / {
                include uwsgi_params;
                uwsgi_read_timeout 3600;
                uwsgi_pass 127.0.0.1:9090;
        }

13、啟動nginx服務:

[root@PYTHON27 /]# /usr/local/nginx/sbin/nginx -t
[root@PYTHON27 /]# /usr/local/nginx/sbin/nginx

14、測試:

[root@PYTHON27 /]# curl http://192.168.75.150/
Hello World

 

源碼:

python-test.py:

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return ["Hello World"]

python-test.ini:

[uwsgi]
socket = 127.0.0.1:9090
wsgi-file = /usr/local/src/python-test/python-test.py
plugins = python
chdir = /usr/local/src/python-test
processes = 2
threads = 2
post-buffering = 8192
buffer-size = 65535
socket-timeout = 10
stats = 127.0.0.1:9191
# callable = python-test
uid = uwsgi
gid = uwsgi
master = true
protocol = uwsgi
buffer-size = 8192
pidfile = /var/run/uwsgi9090.pid
# daemonize = /var/log/uwsgi9090.log

注釋: socket = 127.0.0.1:9090  ##啟動端口9090的服務,需用nginx代理,可以對外提供服務。

    http-socket = 127.0.0.1:9090  ##啟動端口9090的服務,可以直接對外提供服務。

 

python-test.py:通過WEB頁面執行服務器上的腳本:

import os

def application(env, start_response):
    os.chdir('/usr/local/src/python-test')
    retcode = os.system('sh dir.sh')
    if retcode == 0:
        ret = 'success!'
    else:
        ret = 'failure!'
        start_response('200 OK', [('Content-Type','text/html')])
    return [ret]

 

[END]




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM