Flask+uwsgi搭建记录
首先创建uwsgi.ini文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[uwsgi] # uwsgi 启动时所使用的地址与端口 socket = :6543 # 如果不设置会找不到启动文件,报错no python application found chdir=/root/www # python 启动程序文件,一定要设置相对路径,否则在其他目录下找不到文件 wsgi-file = app.py # 获取uwsgi统计信息的服务地址 stats = 127.0.0.1:9191 # 在python文件中 app = Flask(__name__) 的app,否则500 callable = app # 保存pid信息,方便停止服务和重启的时候用 pidfile = uwsgi.pid # 后台运行时记录uwsgi的运行日志,单独运行打开,supervisor配置时注释 #daemonize = uwsgi.log #更新py文件后重启wsgi python-autoreload = 1 |
可与supervisor配置
在supervisord.conf添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[program:Flask] command=/usr/local/python3/bin/uwsgi --ini /root/www/uwsgi.ini # 开始等待时间 startsecs=0 # 停止等待时间 stopwaitsecs=0 user=root autorestart=true autostart=true startretries=3 redirect_stderr=true startsecs=5 stdout_logfile=/root/www/supervisor.log stopasgroup=true killasgroup=true priority=999 |
使用nginx反向代理
1 2 3 4 5 6 7 8 9 10 11 12 |
server { server_name www.domain.com;#网站域名 include /etc/nginx/default.d/*.conf; index index.html index.htm; location /{ include uwsgi_params; uwsgi_pass 127.0.0.1:6543; client_max_body_size 35m; uwsgi_read_timeout 180; } } |
Leave a Comment