【问题标题】:AWS Elastic Beanstalk [error] 2540#0: *1 connect() failed (111: Connection refused) while connecting to upstreamAWS Elastic Beanstalk [错误] 2540#0:*1 连接()失败(111:连接被拒绝),同时连接到上游
【发布时间】:2021-11-17 14:59:47
【问题描述】:

我在尝试使用 AWS Elastic Beanstalk 连接到我的 Django 代码时遇到此错误:

[error] 2540#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.23.63, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"

我的日志显示如下:

----------------------------------------
/var/log/nginx/error.log
----------------------------------------
2020/12/21 03:43:19 [error] 2540#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.23.63, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:43:22 [error] 2540#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.14.160, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:43:34 [error] 2540#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.23.63, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:43:37 [error] 2540#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.14.160, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:43:49 [error] 2540#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.23.63, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:43:52 [error] 2540#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.14.160, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:44:04 [error] 2540#0: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.23.63, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"
2020/12/21 03:44:07 [error] 2540#0: *15 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.14.160, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.14.130"

之前,我也收到了一个错误提示

Dec 21 04:14:38 ip-172-31-14-130 web: Invalid HTTP_HOST header: '172.31.14.130'. You may need to add '172.31.14.130' to ALLOWED_HOSTS.
Dec 21 04:14:38 ip-172-31-14-130 web: Bad Request: /

我确实将 172.31.14.130 添加到我的 settings.py 文件的 ALLOWED_HOSTS 部分,然后收到 /var/log/nginx/error.log 并且当我尝试访问我的网页时,它告诉我该站点花费了太长时间回应 - 任何帮助/建议将不胜感激!

【问题讨论】:

  • 您能否通过 ssh 连接到您的 EB 实例并从内部 curl 您的应用程序以确认它确实有效?
  • @Marcin 我还没有为此实例设置 ssh,但我可以通过 DBeaver 连接到数据库并制作表格,所以我相信它正在工作
  • @ArshiaSharma 你修过吗?在我尝试制作的每个新 django 项目中,我都看到同样的问题导致 502 网关错误
  • @AmanJha 是的,但我相信 502 网关错误与我的问题不同;你检查过弹性豆茎的日志吗?

标签: mysql django amazon-web-services nginx amazon-elastic-beanstalk


【解决方案1】:

你应该使用 express 来监听 8000 端口,因为它会尝试监听 http://127.0.0.1:8000/

const port = process.env.port || 8000;
app.listen(port, ()=>{console.log(`listening on port ${port}....`)})

您还可以在配置 -> 系统 -> 环境属性下的 AWS EB 环境变量中设置端口。下面的例子。

【讨论】:

    猜你喜欢
    • 2016-11-20
    • 2015-04-03
    • 2014-02-26
    • 2012-11-21
    • 2020-03-13
    • 2020-03-14
    • 2020-07-29
    • 2013-11-03
    • 2017-02-09
    相关资源
    最近更新 更多