CentOS6+Flask+Nginx+uWSGI部署小记
公司API服务器转放在阿里云上。因为我平常用的Python Web框架Django要多一点,记下部署Flask需要注意的几点,这不是一篇Step By Step的教程,如果需要看教程,中文的推荐这一篇:http://www.oschina.net/translate/serving-flask-with-nginx-on-ubuntu
安装过程就不说了,其实主要在uWSGI的配置上,uwsgi.ini文件内容如下:
[uwsgi]
#application's base folder
base = /base/youproject #这里是你的项目位置
#python module to import
app = run #对应你的Flask启动文件,我在项目里叫run.py,如果你的是app.py的话,那么这个run改为app
module = %(app)
pythonpath = %(base)
#socket file's location
socket = /base/youproject/%n.sock
#permissions for the socket file
chmod-socket = 666
#the variable that holds a flask application inside the module imported at line #6
callable = app
#location of log files
logto = /var/log/uwsgi/%n.log
daemonize=/var/log/uwsgi/youproject.log
Nginx的配置:
server {
client_max_body_size 20M;
charset utf-8;
listen 80;
server_name www.niubibudeliao.com;
access_log /var/log/nginx/yourproject-access.log;
error_log /var/log/nginx/yourproject-error.log;
location ~^/static/
{
root /base/yourproject/;
expires 24h;
access_log off;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/base/yourproject/uwsgi.sock;
}
}
如果你的uwsgi.ini放在项目目录里的话,这样启动之:
cd /base/yourproject/
uwsgi --ini uwsgi.ini