skip to Main Content

I’ve been setting up an AWS EC2 server this week, and I’m almost there with what I want to do. But opening up as a web server is proving to be a stumbling block.

MY SETUP

I have an AWS EC2 instance running Red Hat EL7.

I have an Apache server running on my instance:

[ec2-user@ip-172-xx-xx-xx ~]$ ps -ef | grep -i httpd
root     18162     1  0 18:02 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   18163 18162  0 18:02 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   18164 18162  0 18:02 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   18165 18162  0 18:02 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   18166 18162  0 18:02 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   18167 18162  0 18:02 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
ec2-user 21345 20507  0 19:03 pts/1    00:00:00 grep --color=auto -i httpd

It seems to be listening on port 80:

[root@ip-172-xx-xx-xx ~]# netstat -lntp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      18162/httpd   

I added inbound rules to the “launch-wizard-1” security group (which is shown as the security group for the instance) for port 80 (HTTP) and 443 (HTTPS) with sources of “0.0.0.0/0” and “::/0”

And finally, for testing my setup, I created an index.html file in my document root (/var/www/html):

<html>
<h1>TEST!</h1>
</html>

THE PROBLEM

From my chrome browser on my computer, when I try to hit:

http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html

I just get:

This page isn’t working
ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com didn’t send any data.
ERR_EMPTY_RESPONSE

(I get the same when I hit one of my domain names which I’ve set up on there, which is what I’m really trying to do of course!)

I’ve tried connecting from Chrome on 2 different computers, and from Safari on my phone (“Safari cannot open the page because it could not connect to the server”)

CHECKS I’VE PERFORMED

I don’t believe I have any server firewall preventing this:

[root@ip-xx-xx-xx-xx conf]# /sbin/iptables -L -v -n
Chain INPUT (policy ACCEPT 3575 packets, 275K bytes)
pkts bytes target     prot opt in     out     source               destination         


Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         


Chain OUTPUT (policy ACCEPT 2215 packets, 350K bytes)
 pkts bytes target     prot opt in     out     source               destination   

Testing with telnet from a terminal session on my mac, port 80 appears to be open. Firstly using the IPv2 Public IP:

telnet 18.xxx.xxx.xx 80

Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.

and using the Public DNS (IPv4):

telnet ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com 80

Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.

And again, the same goes for my domain names – telnet to port 80 shows “Connected”.

– Is the fact that the “foreign host” closes the connection immediately significant? Should it stay open if everything is working as it should?

Running curl on the host correctly returns my simple index.html file:

[ec2-user@ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>

However, running a curl on my local computer – to the server – returns:

curl -v http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80
* Rebuilt URL to: http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80/
*   Trying 18.xxx.xxx.xx...
* Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com (18.xxx.xxx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com
> User-Agent: curl/7.43.0
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com left intact
curl: (52) Empty reply from server

I also tested the webserver “internally” by running google chrome (headless) on the server to create a screenshot, downloaded to my local computer and it shows TEST! (i.e. its working):

google-chrome-stable --headless --disable-gpu --screenshot     http://localhost

One more thing to add – when I attempt the hit the webserver from my local machine, nothing shows in the webserver logs (error_log or access_log) on the server.

So, my opinion is that the web server is up and running, works locally, but is not working correctly for anything coming from “outside”. I’m stumped now though.

2

Answers


  1. Chosen as BEST ANSWER

    Doh! I rebooted the instance and.. all working now!

    22 years working with computers and it took me 22 hrs to resort to a reboot. Fool!


    1. Connect to your EC2 instance using ssh on terminal
    2. Install python if not installed
    3. Start a python server using nohup to continuously use the server

      nohup python -m http.server &

    4. This usually open port 8000, goto EC2 Security Group Make source anywhere or as needed.

    enter image description here

    1. Navigate to the folder having index.html, file path will look like below

      http://ec2-.compute-1.amazonaws.com:8000/folder/website/

    You will be able to develop and see your changes as needed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search