yum -y install python-devel pip install uwsgi pip install flask
上传web文件夹至目标网站目录/home/wwwroot/web
在web下建立文件uwsgi.ini
[uwsgi] # app.py文件所在目录 chdir = /home/wwwroot/web/pyweb callable = app # flask文件名 wsgi-file= app.py # 进程数 processes = 4 threads = 2 max-requests = 100 vacuum = true post-buffering=4096 socket = 127.0.0.1:5000 stats = 127.0.0.1:9010 # 日志输出目录 daemonize = /home/wwwroot/web/pyweb/pyweb.log pidfile = /home/wwwroot/web/pyweb/pyweb.pid
运行uwsgi
uwsgi uwsgi.ini
安装nginx
yum -y install nginx
配置nginx
vim /etc/bin/nginx/nginx.conf
在默认server下添加转发规则,并修改该server的监听端口为8880,以避免与apache端口冲突
server { listen 8880; location /pyweb/static { alias /home/wwwroot/web/pyweb/static; } location /pyweb { include /etc/nginx/uwsgi_params; uwsgi_pass 127.0.0.1:5000; uwsgi_param UWSGI_CHDIR /home/wwwroot/web/pyweb; uwsgi_param UWSGI_SCRIPT pyweb:app; } }
apache充当反向代理角色,将所有请求转发给nginx处理,并返回结果,此处8880为nginx的监听端口
ProxyPass /pyweb http://localhost:8880/pyweb ProxyPassReverse /pyweb http://localhost:8880/pyweb
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com