【问题标题】:heroku django webserver failedheroku django 网络服务器失败
【发布时间】:2013-12-10 22:22:51
【问题描述】:

我第一次使用带有web: python manage.py runserver '0.0.0.0:$PORT' 的Procfile 成功启动,但在第一次git push 之后它因以下错误而崩溃:

OperationalError at /

could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?

重新启动 webrunner 没有帮助。有什么诀窍? heroku 日志输出:

2013-11-25T23:39:56.725138+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
2013-11-25T23:39:56.725138+00:00 app[web.1]:     conn = _connect(dsn, connection_factory=connection_factory, async=async)
2013-11-25T23:39:56.725138+00:00 app[web.1]: OperationalError: could not connect to server: Connection refused
2013-11-25T23:39:56.725138+00:00 app[web.1]:    Is the server running on host "127.0.0.1" and accepting
2013-11-25T23:39:56.725138+00:00 app[web.1]:    TCP/IP connections on port 5432?
2013-11-25T23:39:56.725138+00:00 app[web.1]:     return Database.connect(**conn_params)
2013-11-25T23:39:56.725138+00:00 app[web.1]: 
2013-11-25T23:39:56.872620+00:00 app[web.1]: [26/Nov/2013 00:39:56] "GET / HTTP/1.1" 500 118846

使用 gunicorn 表示无法从 heroku 日志中找到 gunicorn 应用和 app[web.1]: bash: gunicorn: command not found and heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=shrouded-falls-4631.herokuapp.com fwd="188.163.187.182" dyno= connect= service= status=503 bytes=heroku ps 显示崩溃的应用 [web]。至少在第一次开始使用 djangos 的 runserver。但后来也崩溃了。

【问题讨论】:

  • 你跑heroku addons:add heroku-postgresql:dev了吗?

标签: django heroku procfile


【解决方案1】:

我不知道确切的原因,但你为什么要在heroku 上运行django 的runserver? Heroku 使用 gunicorn,它可以执行 project_name/project_name 文件夹中的 .wsgi 文件。

相反,请在 procfile 中使用:“web: gunicorn recipe.wsgi”,以便 gunicorn 为您的 django 应用程序提供服务。只是我的2美分。

此外,如果您使用 0.0.0.0:5432 或 127.0.0.1:5432,它似乎也可以工作。

【讨论】:

  • 使用 gunicorn 表示无法从 heroku 日志中找到 gunicorn 应用程序和 app[web.1]: bash: gunicorn: command not foundheroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=shrouded-falls-4631.herokuapp.com fwd="188.163.187.182" dyno= connect= service= status=503 bytes=,heroku ps 显示崩溃的应用程序 [web]。至少在第一次开始使用 djangos 的 runserver。但后来也坠毁了。
  • 如果你按照heroku网站上的django on heroku教程,你会看到你必须制作requirements.txt文件,gunicorn是一个要求。例如,对于我上一份工作,requirements.txt 有以下要求: Django==1.6 argparse==1.2.1 boto==2.16.0 django-ckeditor==4.0.2 django-registration==1.0 PIL== 1.1.7 Pillow==2.2.1 South==0.8.2 static==0.4 dj-database-url==0.2.2 dj-static==0.0.5 django-storages==1.1.8 gunicorn==18.0 psycopg2 ==2.5.1 wsgiref==0.1.2
  • 我已经在核心文件夹中的requirements.txt 中有-r requirements/develop.txt。我想它应该像本地机器一样捕获它。
  • 只是奇怪为什么它从 requirements.txt 安装只是为了明确声明其中的应用程序,但没有为 -r 这样做
【解决方案2】:

您的数据库未连接。确保您设置了正确的 DATABASE_URL 环境变量,并且您实际上有一个激活的 postgres 计划。

【讨论】:

  • DATABASE_URL 已设置,我认为这不是原因,因为它表示启动 gunicorn 失败。不过谢谢你的回复。
【解决方案3】:

感谢@user2707389,它确实只适用于requirements.txt 中声明的所有应用程序,但我不明白为什么它不使用-r 选项。无论如何,进一步修复 Procfile 和正确的 wsgi.py 让它活着。

【讨论】:

    猜你喜欢
    • 2011-03-27
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2022-07-05
    相关资源
    最近更新 更多