title: Cannot access AWS EC2 server from localhost (curl times out)
body: <p>I'm trying to proxy a node.js server with an ngnix. My issue is that I can't access (curl nor nginx) my node.js server on localhost, </p>
  
  <p>When opening its 3000 port to the exterior, I can see my node js server running. But curl and nginx cannot access it. </p>
  
  <p>One weired thing is that we have a mongodb started and that one can be accessed on localhost without any issues</p>
  
  <p>My instance id is the following : i-0fef394cbc350a4f4</p>
  
  <p>Here's the link to the nginx server that cannot find localhost and therefore times out : <a href="http://ec2-54-246-136-64.eu-west-1.compute.amazonaws.com/" rel="nofollow noreferrer">http://ec2-54-246-136-64.eu-west-1.compute.amazonaws.com/</a></p>
  
  <p>I cannot find another way to demonstrate that we cannot access curl localhost:3000</p>
  
  <pre><code>var sticky = require("socketio-sticky-session");
  sticky(function () {
    // This code will be executed only in slave workers
  
    var http = require('http');
    var socketIO = require('socket.io');
  
    var server = http.createServer(app);
  
    var io = socketIO(server);
    require('./app_api/config/socketio')(io);
  
    io.on('connection', (socket) =&gt; {
      log.trace("new user connected");
      socket.on('disconnect', () =&gt; {
        log.trace("user disconnected");
      });
    });
    connectToDispatcher();
  
    process.title = "share_place";
  
    return server;
  }).listen(3000, function () {
        console.log((cluster.worker ? 'WORKER ' + cluster.worker.id : 'MASTER') + '| PORT ' + 3000)
  
        app.domain.on('error', (er) =&gt; {
          log.error('error', er.stack);
  
          try {
            // make sure we close down within 30 seconds
            var killtimer = setTimeout(() =&gt; {
              process.exit(1);
            }, 30000);
            // But don't keep the process open just for that!
            killtimer.unref();
  
            // stop taking new requests.
            server.close();
  
            // Let the master know we're dead.  This will trigger a
            // 'disconnect' in the cluster master, and then it will fork
            // a new worker.
            cluster.worker.disconnect();
  
            // try to send an error to the request that triggered the problem
            res.statusCode = 500;
            res.setHeader('content-type', 'text/plain');
            res.end('Oops, there was a problem!\n');
          } catch (er2) {
            // oh well, not much we can do at this point.
            log.error('Error sending 500!', er2.stack);
          }
        });
  
      }
  );
  </code></pre>
  
  <p>An even more weired situation : we installed the node code on a beanstalk instance.</p>
  
  <p>We access the node server from the outside : <a href="http://share-place.eu-west-1.elasticbeanstalk.com:8081/" rel="nofollow noreferrer">http://share-place.eu-west-1.elasticbeanstalk.com:8081/</a></p>
  
  <h2>But the default nginx from amazon replies with a connection refused message (for public resources that we can access from the outside)</h2>
  
  <h2>/var/log/nginx/error.log</h2>
  
  <p>2017/04/21 14:32:19 [warn] 3360#0: duplicate MIME type "text/html" in /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf:42
  2017/04/21 14:37:48 [warn] 7358#0: duplicate MIME type "text/html" in /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf:42
  2017/04/21 14:38:41 [error] 7362#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 41.226.2.5, server: , request: "GET / HTTP/1.1", upstream: "<a href="http://127.0.0.1:8081/" rel="nofollow noreferrer">http://127.0.0.1:8081/</a>", host: "share-place.eu-west-1.elasticbeanstalk.com"
  2017/04/21 14:38:41 [error] 7362#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 41.226.2.5, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "<a href="http://127.0.0.1:8081/favicon.ico" rel="nofollow noreferrer">http://127.0.0.1:8081/favicon.ico</a>", host: "share-place.eu-west-1.elasticbeanstalk.com", referrer: "<a href="http://share-place.eu-west-1.elasticbeanstalk.com/" rel="nofollow noreferrer">http://share-place.eu-west-1.elasticbeanstalk.com/</a>"
  2017/04/21 14:38:45 [error] 7362#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 41.226.2.5, server: , request: "GET / HTTP/1.1", upstream: "<a href="http://127.0.0.1:8081/" rel="nofollow noreferrer">http://127.0.0.1:8081/</a>", host: "share-place.eu-west-1.elasticbeanstalk.com"</p>