Cannot connect to AWS EC2 via Nginx from local machine
<p>I have an AWS EC2 instance running Ubuntu that I would like to configure with Nginx. My understanding is that if Nginx is running, and I've configured my server blocks correctly, I should be able to modify my hosts file outside of my VM to serve the public IP from a custom domain.</p>

<p>So in my instance, Nginx is running fine:</p>

<pre><code>~$ /etc/init.d/nginx status
 * nginx is running
</code></pre>

<p>My server block, located at <code>/etc/nginx/sites-available/example.com</code> (which is symlinked to <code>sites-enabled</code>) is as follows:</p>

<pre><code>server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/example;
        index index.html index.htm;

        server_name local.example.com local.www.example.com;

        location / {
                try_files $uri $uri/ =404;
        }
</code></pre>

<p><code>var/www/example/index.html</code> is an existing directory with text to display.</p>

<p>Per other Stackoverflow answers, I've modified my security group to include HTTP port 80:
<a href="https://i.stack.imgur.com/QmxmG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QmxmG.png" alt="enter image description here"></a></p>

<p>When I ping the public IP provided in the AWS interface from my personal machine, I get a response.</p>

<p>But when I run <code>curl -v localhost</code> from inside the instance, I get</p>

<pre><code>* Rebuilt URL to: localhost/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* connect to 127.0.0.1 port 80 failed: Connection refused
* Failed to connect to localhost port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 80: Connection refused
</code></pre>

<p>Further, when I edit my host file like this</p>

<pre><code>my.public.ip    local.example.com
</code></pre>

<p>the connection times out.</p>

<p>Why cannot I not serve my <code>index.html</code> to my dummy domain when I edit my <code>hosts</code> file?</p>