nginx+fastcgi+flask的部署
官方的文档是这样子的
- 建立app.fcgi文件
#!/usr/bin/pythonfrom flup.server.fcgi import WSGIServerfrom yourapplication import appif __name__ == '__main__': WSGIServer(application, bindAddress='/path/to/fcgi.sock').run()
- 配置nginx
location / { try_files $uri @yourapplication; }location @yourapplication { include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SCRIPT_NAME ""; fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;}
官方文档使用的是sock文件,如果想使用ip+端口的形式,也是可以的。
- 建立app.fcgi文件
#!/usr/bin/pythonfrom flup.server.fcgi import WSGIServerfrom yourapplication import appif __name__ == '__main__': WSGIServer(application, bindAddress=('127.0.0.1', 9000)).run() # bindAddress是一个元组,第一个元素是用字串表示的ip地址,第二个元素是int类型的端口号。
- 配置nginx
location / { try_files $uri @yourapplication; }location @yourapplication { include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SCRIPT_NAME ""; fastcgi_pass 127.0.0.1:9000;}