【问题标题】:gunicorn on heruko binding to localhost, without messing up deployment to herukoheroku 上的 gunicorn 绑定到本地主机,而不会弄乱对 heroku 的部署
【发布时间】:2013-08-28 07:38:33
【问题描述】:

这是来自gunicorn on heroku: binding to localhost 的衍生问题。

如何让 gunicorn 在本地(使用工头)和 Heroku 上部署工作?

Procfile 包含:

web: gunicorn mysite.wsgi

当我使用工头在本地部署时,gunicorn 绑定到 http://0.0.0.0:5000。我希望它绑定到127.0.0.1:8000。但是,如果我将 Procfile 更改为:

web: gunicorn -b 127.0.0.1:8000 mysite.wsgi

然后我无法部署到Heroku,浏览器会返回“应用程序错误”

$ heroku ps
=== web (1X): `gunicorn -b 127.0.0.1:8000 mysite.wsgi`
web.1: crashed 2013/08/22 23:45:04 (~ 1m ago)

默认绑定地址设置在哪里和/或我在 Procfile 中放置了哪些 gunicorn 选项以使其在 127.0.0.1 上工作? 我的情况可能有什么独特之处导致默认设置异常(我在 Mac OS 中工作 - 也许是狮子?)

【问题讨论】:

    标签: django heroku gunicorn procfile


    【解决方案1】:

    不要将 gunicorn 绑定到本地 ip。 web: gunicorn -b 127.0.0.1:8000 mysite.wsgi 在您的 procfile 中。这会强制您的 django 应用程序始终使用此本地端口,无论其部署在本地还是在 Heroku 的服务器上。

    使用

    web: gunicorn mysite.wsgi
    

    在您的 procfile 中将使您的应用程序部署在本地 127.0.0.1:8000 和 heroku 的服务器上的 0.0.0.0:5000。我知道您必须在上一个问题中使用 bind 方法才能让 heroku 在本地工作,但该方法仅涵盖未解决的问题。

    使用foreman startweb: gunicorn mysite.wsgi 应该可以工作,正如official docs 所说(以及我自己的经验:))。

    在您的 procfile 中尝试 web: gunicorn mysite.wsgi,将其部署到 heroku 并查看它是否有效。

    https://devcenter.heroku.com/articles/python

    【讨论】:

    • 再次感谢您的快速回复。我已经恢复到 Procfile 的那个版本,它可以工作并且允许我继续工作。但是当在本地运行时,我必须将浏览器指向 0.0.0.0:5000,这感觉不对。所以我回到了最初的问题,正如你所说,它还有一个潜在的问题需要解决。
    • +1 表示返回。因此,您完全按照文档进行操作并遇到了这个问题?您的 mysite 应用程序中是否有任何内容指定要在其上启动的端口? (我猜不是)。再次运行 heroku 示例可能是值得的,或者做一个非常简单的测试项目来看看你是否仍然得到同样的奇怪行为。
    • 这确实是最简单的项目。 hellodjango 教程中的第一步 (devcenter.heroku.com/articles/…)。不,教程没有要求您指定端口,示例屏幕截图显示它应该绑定到 localhost,而不是 0.0.0.0。
    • @Hamlet 是的,我遇到了同样的问题。我将在这周回到它。我会告诉你的。
    • 有人找到解决方案吗?完全相同的问题
    猜你喜欢
    • 2013-08-24
    • 2015-08-07
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2020-05-12
    • 2020-08-25
    • 2017-09-01
    相关资源
    最近更新 更多