[原创]Flask+uwsgi+virtualenv+nginx部署配置

1.创建工程python2.7版本虚目录:
#virtualenv -p /usr/bin/python2.7 CDN_resource
#cd CDN_resource
#source ./bin/activate

2.安装工程依赖的模块:
#pip install -r requirements.txt

3.创建mysql数据库CDN_refresh:
#create database CDN_refresh;

4.配置uwsgi启动文件:
#cat uwsgi.ini
[uwsgi]

socket = 127.0.0.1:5001
pythonpath = /Project/CDN_refresh
file = /Project/CDN_refresh/CDN_Refresh.py
callable = app

uid = www
gid = www

processes = 10
threads = 5
logto = /Project/CDN_refresh/uwsgi.log
pidfile = /Project/CDN_refresh/uwsgi.pid

5.启动uwsgi(写成脚本启停uwsgi)
#uwsgi --ini uwsgi.ini &

6.添加nginx的配置指向uwsgi进程:
server {
listen 5000;
server_name resource.cdn.com;

charset utf-8;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
uwsgi_pass 127.0.0.1:5001;
include uwsgi_params;
#uwsgi_param UWSGI_PYHOME /var/www/<project path>/venv; //python的位置(虚拟环境下)
#uwsgi_param UWSGI_CHDIR /var/www/<project path>; //项目根目录
#uwsgi_param UWSGI_SCRIPT CDN_refresh:app;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

7.平滑启动nginx:
#nginx -s reload

8.后台cron五秒钟执行一次的定时任务脚本
#python refresh_script.py > refresh_scripte.log 2>&1

原文地址:https://www.cnblogs.com/wsjhk/p/8023106.html