【问题标题】:Nginx + Gunicorn + Flask = can only access web app via port domain.com:5555Nginx + Gunicorn + Flask = 只能通过端口 domain.com:5555 访问 web app
【发布时间】:2014-01-21 06:08:51
【问题描述】:

我完全按照这里的说明进行操作: http://www.onurguzel.com/how-to-run-flask-applications-with-nginx-using-gunicorn/

一切似乎都在运行,除了当我访问 domain.com 时,我的网站没有加载。只有当我去域:5555,烧瓶设置运行,我才能访问我的网站。

这是因为我的烧瓶设置为调试模式吗?

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5555, debug=True)

【问题讨论】:

  • 我认为 nginx 正在监听 80....

标签: nginx flask gunicorn


【解决方案1】:

如果您按照帖子中描述的方式进行了配置,那么您需要替换它

proxy_pass http://127.0.0.1:8000;

有了这个

proxy_pass http://127.0.0.1:5555;

不是我见过的最好的 nginx 配置,它使用 'if' 和 If Is Evil,我会在有空的时候为你重写这个配置,只要确保它在这个改变之后能工作,不要'不要忘记跑步

sudo service nginx reload


编辑:对不起,我忘记了,这是我替换 if 的部分
location / {
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    try_files $uri @proxy;
}
location @proxy {
        proxy_pass http://127.0.0.1:8000;
}

你可以试一试,告诉我效果如何。

【讨论】:

    【解决方案2】:

    app.run() 运行您正在使用的应用程序的方法不使用 gunicorn 或 nginx,它正在运行 Flask 的开发 Web 服务器。

    返回您引用的页面并重新阅读有关使用 gunicorn 启动应用程序的部分。一旦您使用 gunicorn 运行应用程序,您可以通过打开 http://127.0.0.1:8000(从您的服务器,而不是从外部)进行测试,然后使用他们提供的配置启动 nginx,这将按照您的预期在您的域中公开该应用程序。

    【讨论】:

      猜你喜欢
      • 2016-04-23
      • 2020-03-11
      • 2019-12-27
      • 2016-06-25
      • 2018-11-04
      • 2014-11-14
      • 2019-12-17
      • 2019-10-26
      • 2021-09-12
      相关资源
      最近更新 更多