【问题标题】:Gunicorn - Can't Access Django Project (Browser Times Out)Gunicorn - 无法访问 Django 项目(浏览器超时)
【发布时间】:2015-11-18 18:01:28
【问题描述】:

使用 AWS 和 Gunicorn,如果我启动 Django 的内置服务器,我的 Django 站点可以访问并且功能齐全,但我无法通过 Gunicorn 访问它。

如果我尝试:

gunicorn MyApp.wsgi

好像启动了:

[2015-11-18 17:53:30 +0000] [18752] [INFO] Starting gunicorn 19.3.0
[2015-11-18 17:53:30 +0000] [18752] [INFO] Listening at: http://0.0.0.0:8001 (18752)
[2015-11-18 17:53:30 +0000] [18752] [INFO] Using worker: sync
[2015-11-18 17:53:30 +0000] [18755] [INFO] Booting worker with pid: 18755

但浏览器只是在基本 URL/IP 地址处返回 Nginx 启动页面,并在尝试访问 <url>:8001<ip_address>:8001 时超时。

如果我运行,我会得到相同的结果:

gunicorn MyApp.wsgi:application --bind 0.0.0.0:8001

编辑:如果我尝试使用特定 URL 代替 0.0.0.0 的相同命令,它会输出以下内容:

[2015-11-18 18:24:17 +0000] [18902] [INFO] Starting gunicorn 19.3.0
[2015-11-18 18:24:17 +0000] [18902] [ERROR] Retrying in 1 second.
[2015-11-18 18:24:18 +0000] [18902] [ERROR] Retrying in 1 second.
[2015-11-18 18:24:19 +0000] [18902] [ERROR] Retrying in 1 second.
[2015-11-18 18:24:20 +0000] [18902] [ERROR] Retrying in 1 second.
[2015-11-18 18:24:21 +0000] [18902] [ERROR] Retrying in 1 second.
[2015-11-18 18:24:22 +0000] [18902] [ERROR] Can't connect to ('myurl.xyz', 8001)

如果我使用服务器的 IP 地址,我会看到:

[2015-11-18 18:26:22 +0000] [18911] [INFO] Starting gunicorn 19.3.0
[2015-11-18 18:26:22 +0000] [18911] [ERROR] Invalid address: ('<my_ip>', 8001)

我花了 3 天的时间试图让 uWSGI 工作,但我在使用 Gunicorn 的第 2 天,我似乎也无法通过这一点。如果第一步不起作用,则没有任何文档或教程指定该怎么做。我对此很陌生,也许我忽略了一些简单的事情,其他人只是认为会得到照顾?

在 Django 设置模块的ALLOWED_HOSTS 部分中正确设置了所有相关的 IP 地址和 URL。

【问题讨论】:

  • 您只是顺便提到了 nginx,但您已明确将其安装为反向代理。所以你需要在这里发布它的配置。
  • 好的,这实际上解决了很多问题。我的印象是,无论 Nginx 是什么,这都会起作用!我会去找Nginx的配置文件。
  • 查看 Gunicorn 文档,似乎我应该能够让 Gunicorn 工作而无需配置 Nginx。我真的希望在尝试设置 Nginx 解决我将面临的无数麻烦之前解决这个问题,因为我需要一种方法来检查未来的解决方案是否有效。如果我停止 Nginx 服务,这可能吗? gunicorn-docs.readthedocs.org/en/latest/run.html#django
  • 可以,但是默认不对外开放8000端口;您要么需要修改负载均衡器/防火墙设置才能打开它,要么在端口 80 上运行 gunicorn(这意味着杀死 nginx 并以超级用户身份启动 gunicorn)。正确设置 nginx 设置要容易得多; gunicorn deploy docs page 上有一个完全可用的配置。
  • 好的,非常感谢您的解释!我已经采用了该示例配置,现在正试图将其提交。不管结果如何,我认为我在这里提出的问题已经得到解答。

标签: python django nginx gunicorn


【解决方案1】:

正如Daniel Roseman 所指出的,亚马逊似乎不允许我在没有额外配置的情况下做我想做的事情。

我接受了建议并配置了 Nginx,现在我可以使用了

gunicorn MyApp.wsgi:application --bind=172.31.21.65:8000

启动它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 2022-12-04
    • 1970-01-01
    • 2015-06-27
    • 2019-01-19
    相关资源
    最近更新 更多