title: Access my AWS EC2 server index.html from external browser
body: <p>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. </p>
  
  <p><strong>MY SETUP</strong></p>
  
  <p>I have an AWS EC2 instance running Red Hat EL7. </p>
  
  <p>I have an Apache server running on my instance:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>It seems to be listening on port 80:</p>
  
  <pre><code>[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   
  </code></pre>
  
  <p>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"</p>
  
  <p>And finally, for testing my setup, I created an index.html file in my document root (/var/www/html):</p>
  
  <pre><code>&lt;html&gt;
  &lt;h1&gt;TEST!&lt;/h1&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>THE PROBLEM</strong> </p>
  
  <p>From my chrome browser on my computer, when I try to hit:</p>
  
  <p><a href="http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html" rel="nofollow noreferrer">http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html</a></p>
  
  <p>I just get:</p>
  
  <pre><code>This page isn’t working
  ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com didn’t send any data.
  ERR_EMPTY_RESPONSE
  </code></pre>
  
  <p>(I get the same when I hit one of my domain names which I've set up on there, which is what I'm <em>really</em> trying to do of course!)</p>
  
  <p>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")</p>
  
  <p><strong>CHECKS I'VE PERFORMED</strong></p>
  
  <p>I don't believe I have any server firewall preventing this:</p>
  
  <pre><code>[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   
  </code></pre>
  
  <p>Testing with telnet from a terminal session on my mac, port 80 appears to be open. Firstly using the IPv2 Public IP:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>and using the Public DNS (IPv4):</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>And again, the same goes for my domain names - telnet to port 80 shows "Connected". </p>
  
  <p><em>- Is the fact that the "foreign host" closes the connection immediately significant? Should it stay open if everything is working as it should?</em></p>
  
  <p>Running curl on the host correctly returns my simple index.html file:</p>
  
  <pre><code>[ec2-user@ip-172-xx-xx-xx ~]$ curl localhost
  &lt;html&gt;
  &lt;h1&gt;TEST!&lt;/h1&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, running a curl on my local computer - to the server - returns:</p>
  
  <pre><code>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)
  &gt; GET / HTTP/1.1
  &gt; Host: ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com
  &gt; User-Agent: curl/7.43.0
  &gt; Accept: */*
  &gt; 
  * 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
  </code></pre>
  
  <p>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):</p>
  
  <pre><code>google-chrome-stable --headless --disable-gpu --screenshot     http://localhost
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>