EC2 instance has apache2 server installed, but I can't connect to it

5,091

Solution 1

When you want to expose a service/port on an EC2 Instance, you need to create a security group which allows connections in that port and attach it to the instance.

So for example, you can create a security group like so: enter image description here

And when you attach it to the instance, it will allow connections on port 80 from all the world (0.0.0.0/0).

Also, I'd check that the server actually listens on this port, run:

netstat -plunt | grep "443 \|80 "

And to see that the server responds:

curl -I http://localhost

Solution 2

Try http, not the default https. This finally worked for me.

Share:
5,091

Related videos on Youtube

sStacker
Author by

sStacker

Updated on September 18, 2022

Comments

  • sStacker
    sStacker almost 2 years

    I have an EC2 instance running Ubuntu 18.04, with apache2 server. I am able to connect to it via PuTTY and via FileZilla and view the server. The server is running, there is the index.html file that's created by apache2 under /var/www, but still when I type in my public IPv4 address in the browser, I cannot connect and view the apache2 welcome page (Cannot connect to it)

    What may be the cause? Is it possible that it's because I am on free tier and I am already running another EC2 instance? (Which is working fine)

    *Edit: I ran the following commands and these are the outputs:

    netstat -plunt | grep "443 \|80 "
    

    (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0
    0 :::80 :::* LISTEN

    curl -I http://localhost
    

    HTTP/1.1 200 OK Date: Mon, 31 Dec 2018 16:39:42 GMT Server: Apache/2.4.29 (Ubuntu) Last-Modified: Mon, 31 Dec 2018 12:54:24 GMT ETag: "2bb4-56f5oe88329x4" Accept-Ranges: bytes Content-Length: 10918 Vary: Accept-Encoding Content-Type: text/html

  • sStacker
    sStacker over 5 years
    I edited the post and added the commands output
  • Itai Ganot
    Itai Ganot over 5 years
    If you run the curl command from outside of the server, which http status code is returned?
  • sStacker
    sStacker over 5 years
    What do you mean outside of the server? where?
  • Itai Ganot
    Itai Ganot over 5 years
    You say that you can't reach the server from the browser, so I mean, instead of trying to reach the server by browser, run the curl command, just not from the server itself. I want to see how the server responds when you try to access it from the world (0.0.0.0/0)
  • sStacker
    sStacker over 5 years
    But where do I type this command then? I am on Windows
  • Itai Ganot
    Itai Ganot over 5 years
  • easwee
    easwee over 4 years
    This worked for me - by default the exposed port in security group is 22 - you need to add HTTP/TCP/80.
  • Code Cooker
    Code Cooker about 4 years
    Exactly this issue I had to fix on my EC2 instance. the port 80 is not exposed by default.
  • Bi Wu
    Bi Wu almost 4 years
    Thanks for saving my time. :D
  • Tominator
    Tominator over 2 years
    Yes! Even though you got downvoted, this was my issue... The link in the EC2 instance page goes to 'https://' but the default apache install only listens to http, causing the browser to say "no worky"