Gunicorn不起作用

3 投票
3 回答
2380 浏览
提问于 2025-04-18 11:24

我正在尝试把我的 Django 应用部署到 Heroku 上。按照官方文档的步骤操作后,我启动的 dyno 总是崩溃。然后我仔细检查了一遍整个过程,我觉得问题可能出在 gunicorn 这部分。

根据说明,我把 Procfile 设置成了 'web: unicorn hellodjango.wsgi',然后当我运行 $foreman start 时,它只显示了 "21:21:07 web.1 | started with pid 77969"。没有显示网页在哪里启动。

接着我想测试一下 gunicorn 是否正常工作。所以我尝试了 "$gunicorn hellodjango.wsgi:application",结果确实不行。

我觉得路径是正确的,因为当前文件夹里有一个 hellodjango 文件夹,里面有一个 wsgi.py 文件。

那可能是什么问题呢?

3 个回答

0

在你的Procfile里写上这个:

web: gunicorn hellodjango.wsgi --log-file -

这样的话,它会把所有的日志信息都显示在屏幕上,像这样:

(your_virtualenv)[~/Projects/myproj]$ foreman start
17:03:57 web.1  | started with pid 79137
17:03:58 web.1  | 2014-10-16 17:03:58 [79137] [INFO] Starting gunicorn 19.0.0
17:03:58 web.1  | 2014-10-16 17:03:58 [79137] [INFO] Listening at: http://0.0.0.0:5000 (79137)
17:03:58 web.1  | 2014-10-16 17:03:58 [79137] [INFO] Using worker: sync
17:03:58 web.1  | 2014-10-16 17:03:58 [79140] [INFO] Booting worker with pid: 79140
0

试着把你的Procfile设置成:

web: gunicorn hellodjango.wsgi:application
2

在gunicorn的后续版本中,有一个变化就是不再把日志输出到标准输出和标准错误了。你可以加上这个参数 --log-file=XXX,然后查看这个日志文件,里面会告诉你它运行在哪个端口上。

撰写回答