nginx+fastcgi+flask的部署,使用ip和端口

nginx+fastcgi+flask的部署

官方的文檔是這樣子的

  • 創建app.fcgi文件
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from yourapplication import app

if __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/python
from flup.server.fcgi import WSGIServer
from yourapplication import app

if __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;
}
相關文章
相關標籤/搜索