Ruby-on-rails 无法通过公共 ip 访问 EC2 实例上的站点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10253484/
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
Can't access site on EC2 instance via public ip
提问by primer
I've been experimenting with EC2 for a couple days and have been banging my head against simply even being able to access the sample site I've hosted. The stack is Rails 3.1.3 with Thin and Nginx.
我已经试用 EC2 几天了,并且一直在反对甚至能够访问我托管的示例站点。堆栈是带有 Thin 和 Nginx 的 Rails 3.1.3。
I've tried several different configurations and finally ended up running the Nginx auto install script, which does return a webpage when I do a curl http://ec2-107-20-143-179.compute-1.amazonaws.com/. However, when I point my browser there, it hangs forever before saying the page cannot be found.
我尝试了几种不同的配置,最终运行了 Nginx 自动安装脚本,当我执行 curl 时它确实返回一个网页http://ec2-107-20-143-179.compute-1.amazonaws.com/. 但是,当我将浏览器指向那里时,它在说找不到页面之前永远挂起。
I have assigned an Elastic IP address, and I've enabled HTTP access via port 80.
我已经分配了一个弹性 IP 地址,并通过端口 80 启用了 HTTP 访问。
I don't much experience with the sysadmin side and I'm basically stumped at this point. Any advice would be greatly appreciated.
我在系统管理员方面没有太多经验,在这一点上我基本上被难住了。任何建议将不胜感激。
回答by Deleteman
Did you enable the http port to all ips? That would be done by going to:
您是否为所有 ip 启用了 http 端口?这将通过以下方式完成:
EC2 -> Security Group -> Default (or your custome one) -> Inbound
EC2 -> 安全组 -> 默认(或您的客户)-> 入站
And then Create a new rule for HTTP and as a source, you should assign: 0.0.0.0/0
然后为 HTTP 创建一个新规则,作为源,您应该分配:0.0.0.0/0
That should do it.
那应该这样做。
回答by Carlton
Think the AWS UI may have been updated but based on Deleteman's answer
认为 AWS UI 可能已更新,但基于 Deleteman 的回答
- Login to EC2 Dashboard
- Instances > Instances
- Actions dropdown > Networking > Change security groups
- You will probably see that you only have launch-wizard-1 allowed which for me only allowed SSH access on port 22
- 登录到 EC2 仪表板
- 实例 > 实例
- 操作下拉菜单 > 网络 > 更改安全组
- 你可能会看到你只允许 launch-wizard-1 这对我来说只允许端口 22 上的 SSH 访问
So as Deleteman mentions, you may need to alter your security groups...
因此,正如 Deleteman 所提到的,您可能需要更改您的安全组...
- Login to EC2 Dashboard
- Network and Security > Security Groups
- Remove any filters that may be in the search box to show all groups
- Personally I edited the default VPC security group as this is a sandbox for me, I imagine you'll want to create a security group for your project
- Select the security group checkbox, select actions dropdown and click "edit the inbound rules", I used the following inbound rules just to be sure it was all working
- 登录到 EC2 仪表板
- 网络和安全 > 安全组
- 删除可能在搜索框中的任何过滤器以显示所有组
- 我个人编辑了默认的 VPC 安全组,因为这对我来说是一个沙箱,我想你会想要为你的项目创建一个安全组
- 选择安全组复选框,选择操作下拉菜单,然后单击“编辑入站规则”,我使用了以下入站规则以确保一切正常


- When you revisit Instances > Instances > Description, you should see the security groups and the rules
- 当您重新访问 Instances > Instances > Description 时,您应该会看到安全组和规则


- Once you are happy it's working I would probably replace all traffic with HTTP and HTTPS if that's all that is needed
- 一旦你满意它的工作,我可能会用 HTTP 和 HTTPS 替换所有流量,如果这就是所需要的
回答by Octopus
I was here earlier looking for a solution to a similar problem I was having. It turns out in my case that the EC2 instance also had its own firewall running in addition to the EC2 security group. The command 'system-config-firewall' let me get in to open the ports. Ports 80 (HTTP) and 3306 (MySQL) were not open by default. 22 (SSH) was open. I also had to do 'yum install system-config-firewall'.
我早些时候在这里寻找解决我遇到的类似问题的方法。在我的案例中,除了 EC2 安全组之外,EC2 实例还运行了自己的防火墙。命令“system-config-firewall”让我进入以打开端口。默认情况下,端口 80 (HTTP) 和 3306 (MySQL) 未打开。22 (SSH) 已打开。我还必须执行“yum install system-config-firewall”。
To summarize, my solution was:
总而言之,我的解决方案是:
> yum install system-config-firewall
> system-config-firewall
回答by user156439
This answer is for the newbies who have no idea what they are doing with an ec2 instance.
这个答案适用于不知道他们在用 ec2 实例做什么的新手。
I was having the same problem and tried all the Security Group fixes to no avail.
我遇到了同样的问题,并尝试了所有安全组修复都无济于事。
As it turns out, I needed to turn on my server from the command line.
事实证明,我需要从命令行打开我的服务器。
sudo service httpd start
Sometimes it's dark, not because a fuse blew, but because you didn't flick the switch.
有时它很黑,不是因为保险丝烧断了,而是因为你没有轻按开关。
回答by jbmyid
I was also struggling with same problem had created security group as well, but did not applied to the instance. Just create new rule for http. And apply from right click instance and choose security group and assign it.
我也在努力解决同样的问题,也创建了安全组,但没有应用于实例。只需为 http 创建新规则。并从右键单击实例中应用并选择安全组并分配它。
回答by David
Octopus' answer was the correct one for me, except for a Windows machine. I needed to go to the Windows Firewall, was blocking all traffic out of the VM if it didn't match a rule. Port 80 wasn't enabled in a rule, so I merely had to add one.
Octopus 的回答对我来说是正确的,除了一台 Windows 机器。我需要转到 Windows 防火墙,如果它与规则不匹配,则会阻止所有流量流出 VM。规则中没有启用端口 80,所以我只需要添加一个。
回答by Parag Tyagi -morpheus-
Very stupid of me as I forgot to install web server(HTTP server) because of which my ec2 instance public IP was not working. Answering this question as this can also be one of the reason which one should not miss as I did.
我很愚蠢,因为我忘记安装Web 服务器(HTTP 服务器),因此我的 ec2 实例公共 IP 无法正常工作。回答这个问题,因为这也可能是我不应该错过的原因之一。
You can install either,
你可以安装,
nginx:
nginx:
sudo apt-get install nginx
apache2:
阿帕奇2:
sudo apt-get install apache2
回答by user8212792
I had the same issue, been racking my brain bad since I have no experience with Ubuntu or linux. The answer from Parag fixed it.
我遇到了同样的问题,因为我没有使用 Ubuntu 或 linux 的经验,所以一直在绞尽脑汁。Parag 的回答修复了它。
Very stupid of me as I forgot to install web server (HTTP server) because of which my ec2 instance public IP was not working. Answering this question as this can also be one of the reason which one should not miss as I did.
我很愚蠢,因为我忘记安装 Web 服务器(HTTP 服务器),因此我的 ec2 实例公共 IP 无法正常工作。回答这个问题,因为这也可能是我不应该错过的原因之一。
You can install either,
你可以安装,
nginx:
nginx:
sudo apt-get install nginx
apache2:
阿帕奇2:
sudo apt-get install apache2
回答by Ananth Kamath
I know this is a very old thread but faced this issue with many services recently. When you are running any application server like Puma or Unicorn over port example 3000, without having a Load Balancer or Proxy like Nginx frontend it. You have to follow two steps:
我知道这是一个非常古老的线程,但最近在许多服务中都遇到了这个问题。当您在端口示例 3000 上运行任何应用程序服务器(如 Puma 或 Unicorn)时,没有像 Nginx 这样的负载均衡器或代理前端。您必须执行以下两个步骤:
- Bind the service to 0.0.0.0/3000 and not 127.0.0.1/3000.(This will leave your service open and accessible by anybody on the internet, that is were step 2 comes into picture).
- In AWS security group now allow port 3000 for 0.0.0.0 if you want it be access by anybody over the internet or add VPN or your network IP to allow it only for you and you team.
- 将服务绑定到 0.0.0.0/3000 而不是 127.0.0.1/3000。(这将使您的服务开放并可供互联网上的任何人访问,即第 2 步进入图片)。
- 在 AWS 安全组中,现在允许端口 3000 用于 0.0.0.0,如果您希望它被互联网上的任何人访问,或者添加 VPN 或您的网络 IP 以仅允许您和您的团队使用它。

