title: "502 Bad Gateway" deploying hapi.js to AWS Beanstalk?
body: <p>I've built a very simple hapi.js app with the following code.</p>
  
  <pre><code>var Hapi = require('hapi');
  var server = new Hapi.Server(3000);
  
  server.route({
      method: 'GET',
      path: '/',
      handler: function (request, reply) {
          reply('Hello, world!');
      }
  });
  
  server.start(function () {
      console.log('Server running at:', server.info.uri);
  });
  </code></pre>
  
  <p>However I keep getting a "502 Bad Gateway" error upon deploy. I'm using a standard zip &amp; upload method to deploy. The zip file contains a service.js file with the code above and a package.json file as shown below.</p>
  
  <pre><code>{
    "name": "hapi_aws_testing",
    "version": "0.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
      "hapi": "^6.4.0"
    },
    "engines"        : {
      "node": "0.10.26"
    }
  }
  </code></pre>
  
  <p>I've tried deploying with the node.js engines section removed, and also set it to 0.10.29 and then realized that the version of node.js available in Beanstalk on the 1.0.4 AMI images was 0.10.26, so changed it here to that version. I've tried it locally and all runs well.</p>
  
  <p>In the error log I've got the following two logs that show the code running...</p>
  
  <pre><code>-------------------------------------
  /var/log/nodejs/nodejs.log
  -------------------------------------
  Server running at: http://ip-172-31-3-9:3000
  </code></pre>
  
  <p>and then the errors when I try to hit the server with a browser.</p>
  
  <pre><code>-------------------------------------
  /var/log/nginx/error.log
  -------------------------------------
  2014/08/12 02:07:24 [error] 3457#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.13.177, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "consociation-test.elasticbeanstalk.com"
  2014/08/12 02:07:26 [error] 3457#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.13.177, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "consociation-test.elasticbeanstalk.com"
  </code></pre>