AWS Elastic Beanstalk Django 应用程序健康检查问题
Posted
技术标签:
【中文标题】AWS Elastic Beanstalk Django 应用程序健康检查问题【英文标题】:AWS Elastic Beanstalk Django application health check problem 【发布时间】:2021-02-18 02:39:06 【问题描述】:我遇到了与here 描述的问题非常相似的问题。由于该问题没有得到解答,而且我的问题与那里描述的问题之间存在一些差异,我决定提出一个新问题。
我设法将我的 Django 后端 API 部署到 AWS Elastic Beanstalk Amazon Linux 2 Python 3.7 平台。但是,EB 实例的健康状态为“严重”。它显示了消息:
以下服务未运行:发布。
整体运行状况为“降级”,消息为
所有实例上的服务受损。
有时会出现一条消息,指出所有响应都是 4xx。这个消息来来去去。奇怪的是,我配置了 2 个负载均衡器(一个用于 http,另一个用于 https),并且两者都有应用程序中有效 url 的健康检查路径 url。
我能找到的唯一相关日志如下:
daemon.log
F, [2020-11-05T00:07:40.486088 #15846] FATAL -- : /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/launcher.rb:432:in `block in setup_signals': SIGTERM (SignalException)
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/single.rb:117:in `join'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/single.rb:117:in `run'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/launcher.rb:172:in `run'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/puma-4.3.5/lib/puma/cli.rb:80:in `run'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/healthd-1.0.6/bin/healthd:112:in `block in <top (required)>'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/healthd-1.0.6/bin/healthd:19:in `chdir'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.6.0/gems/healthd-1.0.6/bin/healthd:19:in `<top (required)>'
from /opt/elasticbeanstalk/lib/ruby/bin/healthd:23:in `load'
from /opt/elasticbeanstalk/lib/ruby/bin/healthd:23:in `<main>'
web.stdout.log
(...)
Nov 5 09:26:18 ip-172-31-94-128 web: Invalid HTTP_HOST header: '52.86.81.51'. You may need to add '52.86.81.51' to ALLOWED_HOSTS.
Nov 5 09:26:18 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:33:11 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:11 ip-172-31-94-128 web: Bad Request: /console/
Nov 5 09:33:12 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:12 ip-172-31-94-128 web: Bad Request: /index.php
Nov 5 09:33:16 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:16 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:33:16 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:16 ip-172-31-94-128 web: Bad Request: /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
Nov 5 09:33:17 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:17 ip-172-31-94-128 web: Bad Request: /api/jsonws/invoke
Nov 5 09:33:20 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:20 ip-172-31-94-128 web: Bad Request: /solr/admin/info/system
Nov 5 09:33:22 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:22 ip-172-31-94-128 web: Bad Request: /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
Nov 5 09:33:24 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:24 ip-172-31-94-128 web: Bad Request: /wp-content/plugins/wp-file-manager/readme.txt
Nov 5 09:33:25 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 09:33:25 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:35:29 ip-172-31-94-128 web: Not Found: /boaform/admin/formLogin
Nov 5 09:35:55 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.212.192.113'. You may need to add '18.212.192.113' to ALLOWED_HOSTS.
Nov 5 09:35:55 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:41:21 ip-172-31-94-128 web: Invalid HTTP_HOST header: '54.243.237.110'. You may need to add '54.243.237.110' to ALLOWED_HOSTS.
Nov 5 09:41:21 ip-172-31-94-128 web: Bad Request: /remote/login
Nov 5 09:46:37 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.212.192.113'. You may need to add '18.212.192.113' to ALLOWED_HOSTS.
Nov 5 09:46:37 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:49:41 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.212.192.113'. You may need to add '18.212.192.113' to ALLOWED_HOSTS.
Nov 5 09:49:41 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:58:26 ip-172-31-94-128 web: Not Found: /
Nov 5 09:59:35 ip-172-31-94-128 web: Invalid HTTP_HOST header: '34.236.195.107'. You may need to add '34.236.195.107' to ALLOWED_HOSTS.
Nov 5 09:59:35 ip-172-31-94-128 web: Bad Request: /
Nov 5 09:59:35 ip-172-31-94-128 web: Invalid HTTP_HOST header: '34.236.195.107'. You may need to add '34.236.195.107' to ALLOWED_HOSTS.
Nov 5 09:59:35 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:09:52 ip-172-31-94-128 web: Invalid HTTP_HOST header: '52.86.81.51'. You may need to add '52.86.81.51' to ALLOWED_HOSTS.
Nov 5 10:09:52 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:10:35 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.212.192.113'. You may need to add '18.212.192.113' to ALLOWED_HOSTS.
Nov 5 10:10:35 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:10:38 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.212.192.113'. You may need to add '18.212.192.113' to ALLOWED_HOSTS.
Nov 5 10:10:38 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:20:03 ip-172-31-94-128 web: Invalid HTTP_HOST header: '52.86.81.51'. You may need to add '52.86.81.51' to ALLOWED_HOSTS.
Nov 5 10:20:03 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:23:53 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 10:23:53 ip-172-31-94-128 web: Bad Request: /remote/login
Nov 5 10:36:49 ip-172-31-94-128 web: Invalid HTTP_HOST header: '34.236.195.107'. You may need to add '34.236.195.107' to ALLOWED_HOSTS.
Nov 5 10:36:49 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:38:39 ip-172-31-94-128 web: Invalid HTTP_HOST header: '54.243.237.110'. You may need to add '54.243.237.110' to ALLOWED_HOSTS.
Nov 5 10:38:39 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:42:26 ip-172-31-94-128 web: Not Found: /
Nov 5 10:42:49 ip-172-31-94-128 web: Invalid HTTP_HOST header: '52.86.81.51'. You may need to add '52.86.81.51' to ALLOWED_HOSTS.
Nov 5 10:42:49 ip-172-31-94-128 web: Bad Request: /
Nov 5 10:42:49 ip-172-31-94-128 web: Invalid HTTP_HOST header: '52.86.81.51'. You may need to add '52.86.81.51' to ALLOWED_HOSTS.
Nov 5 10:42:49 ip-172-31-94-128 web: Bad Request: /
Nov 5 11:05:54 ip-172-31-94-128 web: Invalid HTTP_HOST header: '18.210.4.127'. You may need to add '18.210.4.127' to ALLOWED_HOSTS.
Nov 5 11:05:54 ip-172-31-94-128 web: Bad Request: /
我不知道 daemon.log 中的错误是什么意思。我用谷歌搜索了这个错误,没有发现任何相关的东西。另一方面,我不明白为什么会发出出现在 web.stdout.log 中的请求。发起请求的 IP 地址都来自美国弗吉尼亚州(我的服务器所在的地区),所以我猜测这些请求是由某些 AWS 资源发出的。奇怪的是发出请求的路由:我的应用程序中都不存在这些路由。
非常感谢任何帮助。提前谢谢你。
【问题讨论】:
是负载均衡的EB环境吗?负载均衡器的运行状况检查设置如何? 嗨@Marcin,再次感谢您的回答。正如我在问题中提到的,我已经配置了两个负载均衡器,它们的健康检查路径是一个有效的 url。您指的还有哪些其他健康检查设置? 【参考方案1】:快速解决方案:
您需要在项目的settings.py
中添加*
→ ALLOWED_HOSTS
ALLOWED_HOSTS = ['*']
长解:
看起来您的 IP 地址是动态的,因此您需要通过域名而不是 IP 访问,或者您需要允许所有 IP,这意味着 快速解决方案。
解释here 同problem
【讨论】:
就是这样!我将尝试找到一种方法来实施长期解决方案,因为不建议将快速解决方案用于生产,但它解决了问题。谢谢@rzlvmp以上是关于AWS Elastic Beanstalk Django 应用程序健康检查问题的主要内容,如果未能解决你的问题,请参考以下文章
AWS Elastic Beanstalk CLI 安装错误