
正文
nginx 代理flask应用的uwsgi配置
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
socket代理配置:
关于uwsgi的用法,请自行百度,这里只针对socket文件和端口的不同,进行单一的记录。
这种方式启动的flask应用,由于是通过socket与nginx通信的,所以必须制定socket文件,无法进行集群部署:
uwsgi配置
[uwsgi]
#application's base folder
base = /data/www/myproject#python module to import
app = manage
module = %(app)home = %(base)/venv
pythonpath = %(base)#socket file's location
socket = /data/www/myproject/%n.sock#permissions for the socket file
chmod-socket = #the variable that holds a flask application inside the module imported at line #
callable = app#location of log files
logto = /data/www/log/uwsgi/%n.log
nginx配置:
server {
listen ;
server_name localhost;
charset utf-;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass unix:/data/www/myproject/myproject_uwsgi.sock;
}
}
socket端口配置:
如果需要使用集群,需要使用端口来与nginx进行通信,那么uwsgi的配置就会有些许的差异:
uwsgi配置
[uwsgi]
#application's base folder
base = /data/www/myproject#python module to import
app = hello
module = %(app)home = %(base)/venv
pythonpath = %(base)#socket file's location
socket = :
#socket = /data/www/myproject/%n.sock
#permissions for the socket file
chmod-socket =
#the variable that holds a flask application inside the module imported at line #
callable = app
#location of log files
logto = /data/www/log/uwsgi/%n.log
差异就是将sock文件,改为端口,当然也可以写成如下格式:
socket = 0.0.0.0:
socket = 127.0.0.1:
那么如果nginx需要负载两台甚至多台server,就需要修改配置:
upstream ai-server {
server server1:;
server server2:;
}
server {
listen ;
server_name localhost;
charset utf-;
client_max_body_size 75M; location / {
include uwsgi_params;
uwsgi_pass ai-server;
}
}






