1、安装 uwsgi
# pip uwsgi
如果没有 pip ,请先安装 python3 ,然后在 /usr/bin 里面建立软件
[root@iZ23ugsp2h3Z bin]# ll pip* lrwxrwxrwx 1 root root 4 Dec 3 17:38 pip -> pip3 lrwxrwxrwx 1 root root 27 Nov 30 11:10 pip3 -> /usr/local/python3/bin/pip3
2、编写一个简单 python 程序 foobar.py。
#!/usr/bin/python
#coding=utf-8
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]3、部署在 http 端口 9090:
这种部署,可以直接通过 IP+端口方式访问到,但是无法通过 nginx 转发,之前一直失败,就是这样导致的。
uwsgi --http :9090 --wsgi-file foobar.py uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2 uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
4、通过 Nginx 转发,部署在 socket
先配置 nginx
server{
listen 80;
server_name test.py.php.cn;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
}
access_log /.../test.py.php.cn.log access;
error_log /..../test.py.php.cn.error.log error;
}然后开启 uwsgi 服务,绑定端口 9090
uwsgi --socket 127.0.0.1:9090 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191