【问题标题】:ERR_CONNECTION_TIMED_OUT while deploying django using AWS elastic beanstalk(with nginx + gunicorn)使用AWS弹性beantalk(使用nginx + gunicorn)部署django时出现ERR_CONNECTION_TIMED_OUT
【发布时间】:2020-10-23 17:56:14
【问题描述】:

我在使用 aws elastic beanstalk 部署 django 时遇到 ERR_CONNECTION_TIMED_OUT。

当前状态

  1. 控制台显示它已正确部署。 (向我显示 OK 状态)
  2. 允许安全组的入站流量。

但是,当我尝试使用弹性 beanstalk 提供的 url 连接实例时,我总是在 chrome 浏览器上看到 ERR_CONNECTION_TIMED_OUT。

我尝试过的事情。

  1. 检查了nginx日志,没有打印出来。所以我怀疑负载均衡器没有将请求路由到 nginx Web 服务器。
tail -f /var/log/nginx/*
  1. 使用 ssh 连接 ec2 实例,检查 nginx 使用 80 端口运行,gunicorn 使用 8000 端口运行
[ec2-user@ip-172-31-0-29 ~]$ sudo lsof -i -P -n | grep LISTEN
rpcbind  2650      rpc    8u  IPv4  16321      0t0  TCP *:111 (LISTEN)
rpcbind  2650      rpc   11u  IPv6  16324      0t0  TCP *:111 (LISTEN)
master   3130     root   13u  IPv4  18639      0t0  TCP 127.0.0.1:25 (LISTEN)
sshd     3328     root    3u  IPv4  20466      0t0  TCP *:22 (LISTEN)
sshd     3328     root    4u  IPv6  20475      0t0  TCP *:22 (LISTEN)
ruby     3475  healthd    6u  IPv4  22081      0t0  TCP 127.0.0.1:22221 (LISTEN)
nginx    4778     root    6u  IPv4 392465      0t0  TCP *:80 (LISTEN)
nginx    4780    nginx    6u  IPv4 392465      0t0  TCP *:80 (LISTEN)
gunicorn 4796   webapp    5u  IPv4 392820      0t0  TCP 127.0.0.1:8000 (LISTEN)
gunicorn 4806   webapp    5u  IPv4 392820      0t0  TCP 127.0.0.1:8000 (LISTEN)
gunicorn 4807   webapp    5u  IPv4 392820      0t0  TCP 127.0.0.1:8000 (LISTEN)
gunicorn 4808   webapp    5u  IPv4 392820      0t0  TCP 127.0.0.1:8000 (LISTEN)

谁能帮我找出问题所在? 提前致谢!

【问题讨论】:

  • 默认端口不是5000,不是8000吗?如果您更改了端口,您是否相应地调整了 EB 设置?
  • 也是单实例还是负载均衡环境?
  • AFAIK,gunicorn的默认端口是8000。我只使用一个单实例,如何查看我的实例是否负载均衡环境?感谢您的快速评论!
  • 哦,我刚刚发现了问题,我刚刚从中间件设置中删除了“django.middleware.security.SecurityMiddleware”,它就开始工作了……
  • 当然,请这样做,然后我会接受你的。

标签: django nginx amazon-elastic-beanstalk gunicorn


【解决方案1】:

基于 cmets。

问题原来是由于 django 设置django.middleware.security.SecurityMiddleware:

django.middleware.security.SecurityMiddleware 为请求/响应周期提供了多项安全增强功能。每个都可以通过设置独立启用或禁用。

移除设置解决了问题。

【讨论】:

    猜你喜欢
    • 2016-11-29
    • 1970-01-01
    • 2012-08-24
    • 2023-03-15
    • 2020-12-26
    • 2018-08-17
    • 2016-10-27
    • 2013-12-08
    • 2018-03-26
    相关资源
    最近更新 更多