Can't access site on EC2 instance via public ip
Asked Answered
P

25

92

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.

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.

I have assigned an Elastic IP address, and I've enabled HTTP access via port 80.

I don't much experience with the sysadmin side and I'm basically stumped at this point. Any advice would be greatly appreciated.

Phenformin answered 20/4, 2012 at 21:0 Comment(3)
I just looked in my chrome at your url - it's working for me - maybe a browser caching issue?Donal
Yes it is working now, massive case of user error. Thanks!Phenformin
Answer already given in other places, but in case anyone stumbles on this: on a Windows AMI, the Window firewall (not AWS) might be blocking everything. As soon as I disabled it, everything worked like a charm. Probably not the right thing to do, but this is the issue.Selfgoverned
S
144

Did you enable the http port to all ips? That would be done by going to:

EC2 -> Security Group -> Default (or your custome one) -> Inbound

And then Create a new rule for HTTP and as a source, you should assign: 0.0.0.0/0

That should do it.

Sanjay answered 20/4, 2012 at 21:7 Comment(3)
I do in fact have a rule defined for HTTP. Its the EC2 default, listening at port 80 with all IP address allowedPhenformin
And is your web server si listening to port 80?Sanjay
In the end I was initializing instances using the default security group -- which I mistakenly thought I had correctly set up. In fact I had defined a custom group with the proper settings. Stupid error on my part.Phenformin
W
53

Think the AWS UI may have been updated but based on Deleteman's answer

  • 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

So as Deleteman mentions, you may need to alter your security groups...

  • 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

Rules

  • When you revisit Instances > Instances > Description, you should see the security groups and the rules

enter image description here

  • Once you are happy it's working I would probably replace all traffic with HTTP and HTTPS if that's all that is needed
Woodhouse answered 3/12, 2014 at 13:21 Comment(4)
Opening all ports from "everywhere" is a very bad idea.Overdone
good quality answer, one point I had have to restart the instance for the new rules to work.Lilienthal
Open port 80 for access from "everywhere" usually is enough. Maybe 443 for HTTPS.Columniation
Can't explain how much this saved me, been searching for this since days. Thanks a lotCartelize
B
27

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'.

To summarize, my solution was:

> yum install system-config-firewall
> system-config-firewall
Bronco answered 20/7, 2012 at 0:16 Comment(7)
The first one gives Setting up Install Process No package system-config-firewall available. Nothing to doHeall
This was exactly what I needed to do.Vault
Good stuff, this was my initial problem as well! Thank you!!Anabolite
after messing (unsuccessfully) with iptables for a while, this one solved it for me. Thanks!Forthright
Perfect, I was stuck with this for one day! Thanks mate :)Willams
For me me it was system-config-firewall-tui, but definitely a big help. I was going crazy :)Durkin
sudo yum -y install system-*Perkins
B
22

This answer is for the newbies who have no idea what they are doing with an ec2 instance.

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.

Bambibambie answered 7/5, 2013 at 16:39 Comment(1)
lol thank you much. I've been wondering why I am seeing twitter bootstrap's site bookmark icon appearing (hint), but the site not loading.Expedite
F
22

I have faced the same issue multiple times with the ubuntu EC2 instance and here I am adding all the methods which helped me in fixing the issue in different situations.

  1. Make sure you are accessing the "Public IPv4 DNS" or "Public IPv4 address" or "Elastic IP addresses" from the browser.

Step1 screenshots

  1. Check whether port 80 is open or not. Step2 port 80 is not open Here you can see that port 80 is not open in Inbound rules. So let's open port 80 first. For this click on the security tab and you can see the Security groups open this new tab Security group Now you have to edit inbound rules. Edit inbound rules Click at add rule Then select type HTTP and source AnyWhere and save it. enter image description here Similarly, you do HTTPS also.

  2. Check the browser URL if HTTPS is not enabled and if we try to access from browser default it might be HTTPS if so please make it HTTP and try again.

  3. Edit Network ACL. Select the Networking tab and open Subnet ID in a new window. Networking tab and subnet Id

Opened subnet Id From Subent Id open Network ACL in the new window Now edit inbound rules. Edit inbound rule 100 Rule 100 should look like this, i.e, type=="HTTP"

Fullblooded answered 12/5, 2021 at 13:10 Comment(2)
This was surely helpful. Thanks a lot!Jetport
You are welcome @SapinderSingh. I have faced it many times; that's the reason for the detailed steps, and I know it helps a lot of people. And Thanks for the recognitionFullblooded
A
12

For me, It was as simple as just changing the url from https://my-site to http://my-site on my browser. (This solution only applies to people who are still able to SSH onto the ec2 instance but cannot connect via browser)

Antepast answered 11/7, 2021 at 3:42 Comment(3)
For those who can access it from anywhere (curl command, safari etc.) but can not access from google chrome, this saved my life. But i could not understand why "https" not working eventhough i made proper configurations (security groups inbound rules etc.)?Brathwaite
@UtkuCan probably because you don't have an SSL certificate installed on your instance, or don't have anything running at that port.Antepast
Thank u, thats rlly helps, cuz i assigned HTTP on 80, but default AWS link is on HTTPS and I just haven't mention itBowshot
W
7

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.

Wychelm answered 13/4, 2014 at 10:58 Comment(3)
I had the same problem and after reading this, noticed in my instance settings that it did not have my security group associated. The latest UI has an "actions" drop down that I used to "change security groups"Mortify
@JimClouse Thanks, that was the missing step for me.Vermin
it's a little confusing the way the dashboard is. So you see a security groups on the left pane. You add a new security group assuming that you are adding it to your instance. And that's where all hell breaks loose. :) Thanks @Wychelm for making it explicit on how to do this.Vagrancy
Y
5

In my case, it's because I access the public IP with HTTPS, so remmeber to remove 's' in the browser. So stupid!

Yumuk answered 9/12, 2022 at 10:13 Comment(0)
P
3

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.

Plasticine answered 27/11, 2013 at 4:16 Comment(0)
C
3

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.

You can install either,

nginx:

sudo apt-get install nginx

apache2:

sudo apt-get install apache2
Chryselephantine answered 8/12, 2015 at 16:29 Comment(0)
T
2

I have encountered a quite similar situation when I tried to run my go app on EC2. If you cannot see an appropriate message or result on your browser even though you:

  • can get a response well using curl,
  • finished configuring the Security Group properly
    • open pen inbound traffic for 80, 443 for the world or for your IP address and
    • open inbound traffic for 22; and
    • open inbound traffic for a port that you use (like 8080, 4343, etc.)), and;
  • run your app to accept a connection from the outside (npm app.js, go run . etc.)

Make sure that you entered http://ec2-..., instead of https://ec2-... on your browser. You cannot connect to the server with https:// even though you open 443 port, unless you already configured ssh certificate. Entering the full address with http protocol, without omitting it, may solve the problem.

Tejeda answered 26/6, 2021 at 22:9 Comment(1)
Make sure that you entered ec2-..., instead of ec2-... on your browser. it solves the issueLatoya
H
1

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.

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.

You can install either,

nginx:

sudo apt-get install nginx

apache2:

sudo apt-get install apache2
Huynh answered 25/6, 2017 at 18:31 Comment(1)
Used nginx recently.Spumescent
G
1

The best way is to edit your security inbound rules. Please refer to below snap.

enter image description here

Gaullism answered 8/1, 2022 at 13:57 Comment(0)
D
1

While we opened inbounds rules http and https it goes automatically with either one http or https so follow below: Make sure that you entered http://ec2-..., instead of https://ec2-... on your browser.

Dafna answered 13/6, 2022 at 22:13 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Faille
L
1

it may solve by putting http instead of https in browser address

Latoya answered 7/2, 2023 at 18:44 Comment(0)
E
0

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:

  1. 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).
  2. 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.
Erbe answered 19/5, 2020 at 16:53 Comment(0)
C
0

My problem was the browser.

Chrome works; Firefox DOES NOT work.

Catamenia answered 15/3, 2021 at 6:24 Comment(0)
Q
0

Here are the steps that you can follow and when you check both of these, chances are that they will work for sure.

  1. Make sure that you're using http:// in the browser instead of https:// on the IP and amazon IPV4 public DNS (It comes in some form like http://ec2-some-ip-address-here.region.compute.amazonaws.com)

  2. Click on the instance id and scroll down,

go to the security tab,

click on security group it will look like this [![enter image description here][1]][1]

Click on edit inbound rules

Add this

For type- choose HTTP
Source - choose anywhere or anywhere ipv4

and click save and you're done.

Combination of these two should work fine.

Quotient answered 21/12, 2021 at 10:34 Comment(0)
I
0

For me, I needed to setup ufw and allow it on my EC2insttance. I did so with this command sudo ufw app info "WWW Full"

Iridescent answered 7/11, 2022 at 9:56 Comment(0)
G
0

If you spent so much time trying to solve this issue with no advantage, i would suggest you to make a fresh instance and allow http and https from the check box you get during the creation of the instance. It helped me solve the problem.

Gardner answered 5/7, 2023 at 14:29 Comment(0)
C
0

Maybe do you need to change the Type Info to All TCP in inbound rules of the instance. enter image description here

Commentary answered 26/9, 2023 at 14:18 Comment(0)
S
0

It might be an issue with only allowing port 0, rather than all ports. If you're using terraform, then this creates a rule just allowing traffic on port 0

ingress {
  from_port   = 0
  to_port     = 0
  protocol    = "tcp"
  cidr_blocks = ["0.0.0.0/0"]
}

which is different from this, which allows traffic to all ports

ingress {
  from_port   = 0
  to_port     = 0
  protocol    = "-1"
  cidr_blocks = ["0.0.0.0/0"]
}
Shool answered 29/11, 2023 at 21:25 Comment(0)
B
0

I have been trying run a python server in port. What turns out is, at the end make sure host = '0.0.0.0' is added.

if __name__ == '__main__':
port = int(os.environ.get('PORT', 3001)
app.run(host='0.0.0.0', port=port, debug=True)

To run the public address without port, make sure a webserver like nginx is running.

And http works not https.

Bobbitt answered 15/2 at 12:48 Comment(0)
B
0

In both cases if you check on ec2 can continue to be block from accessing port 80 of public IP. You should check on the service firewall running on your instance. My case I have to stop this service before I could access my elastic public IP

sudo systemctl stop firewalld
Banbury answered 6/5 at 20:33 Comment(0)
T
-2

My Windows Ec2 instance was not accessible when I tried to access the public IP from the browser. After checking all the above, I had to update the Windows (Defender) Firewall setting which was blocking the incoming traffic.

Transported answered 4/8, 2021 at 12:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.