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

Posted wsjhk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原创]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

 




































以上是关于[原创]Flask+uwsgi+virtualenv+nginx部署配置的主要内容,如果未能解决你的问题,请参考以下文章

flask使用工厂函数后怎么用uwsgi启动?

如何使用 Flask+uWSGI 设置自动重载?

flask项目下的uwsgi配置方式及示例

flask uwsgi nginx

uwsgi + nginx + flask:上游过早关闭

上游超时(uWSGI + NGINX + Flask)