scala 使用 Boxfuse 将播放框架应用程序部署到 Amazon AWS 时出现“主机不允许”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45070168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"host not allowed" error when deploying a play framework application to Amazon AWS with Boxfuse
提问by Haijin
I am trying to deploy a simple web application written using Play Framework in Scala to Amazon web service.
我正在尝试将使用 Scala 中的 Play Framework 编写的简单 Web 应用程序部署到 Amazon Web 服务。
The web application is running OK in development mode and production mode in my local machine, and I've changed its default port to 80.
Web 应用程序在我的本地机器上以开发模式和生产模式运行正常,我已将其默认端口更改为 80。
I used Boxfuse to deploy to AWS as suggested.
我按照建议使用 Boxfuse 部署到 AWS。
I first run "sbt dist" then "boxfuse run -env=prod"
我首先运行“ sbt dist”然后“ boxfuse run -env=prod”
Things went well as desired. The image is fused and pushed to AWS. AMI is created. Instance was started and my application was running.
事情进展顺利。图像被融合并推送到 AWS。AMI 已创建。实例已启动,我的应用程序正在运行。
i-0f696ff22df4a2b71 => 2017-07-13 01:28:23.940 [info] play.api.Play - Application started (Prod)
i-0f696ff22df4a2b71 => 2017-07-13 01:28:23.940 [info] play.api.Play - 应用程序启动(Prod)
Then came the error message:
然后是错误信息:
WARNING: Healthcheck (http://35.156.38.90/) returned 400 instead of 200. Retrying for the next 300 seconds ...
i-0f696ff22df4a2b71 => 2017-07-13 01:28:24.977 [info] p.c.s.AkkaHttpServer - Listening for HTTP on /0.0.0.0:80
i-0f696ff22df4a2b71 => 2017-07-13 01:28:25.512 [warn] p.f.h.AllowedHostsFilter - Host not allowed: 35.156.38.90
警告:健康检查 ( http://35.156.38.90/) 返回 400 而不是 200。在接下来的 300 秒内重试......
i-0f696ff22df4a2b71 => 2017-07-13 01:28:24.977 [info] pcsAkkaHttpServer - 在 /0.0.0.0:80 上监听 HTTP
i-0f696ff22df4a2b71 => 2017-07-13 01:28:25.512 [警告] pfhAllowedHostsFilter - 不允许主机:35.156.38.90
The instance was terminated after repeated try after 3 minutes. It gave a warning like:
实例在 3 分钟后重复尝试后终止。它发出了如下警告:
Ensure your application responds with an HTTP 200 at / on port 80
确保您的应用程序在 80 端口/上以 HTTP 200 响应
But I've made sure the application responds in local machine, and I tried both Windows and Ubuntu, all works well.
但是我已经确保应用程序在本地机器上响应,并且我尝试了 Windows 和 Ubuntu,一切正常。
Also, running "boxfuse run" on local machine, I can connect to it using "http://localhost", but still have the error.
另外,在本地机器上运行“boxfuse run”,我可以使用“ http://localhost”连接到它,但仍然有错误。
Hope someone with experience can give me some suggestions. Thanks in advance.
希望有经验的人能给我一些建议。提前致谢。
ps: not sure if relevant, I added these settings to application.conf
ps:不确定是否相关,我将这些设置添加到 application.conf
http {
address = 0.0.0.0
port = 80
}
回答by Leo C
Judging from the error message, it looks like the problem might be related to play.filters.hosts.allowednot set up in application.conf. The filter lets you configure which hosts can access your application. More details about the Play filter is available here.
从错误信息来看,问题似乎与play.filters.hosts.allowed未设置有关application.conf。过滤器允许您配置哪些主机可以访问您的应用程序。此处提供了有关播放过滤器的更多详细信息。
Here's a configuration example:
这是一个配置示例:
play.filters.hosts {
allowed = ["."]
}
Note that allowed = ["."]matches all hosts hence would not be recommended in a production environment.
请注意,allowed = ["."]在生产环境中不建议匹配所有主机。
回答by Axel Fontaine
As stated in the Boxfuse Play Documentation:
If your application uses the allowed hosts filter you must ensure play.filters.hosts.allowed in application.conf allows connections from anywhere as this filter otherwise causes ELB healthchecks to fail. For example:
如果您的应用程序使用允许的主机过滤器,您必须确保 application.conf 中的 play.filters.hosts.allowed 允许来自任何地方的连接,否则此过滤器会导致 ELB 健康检查失败。例如:
play.filters.hosts {
allowed = ["."]
}
More info in the official Play documentation.
官方 Play 文档中的更多信息。

