502 Bad Gateway on nginx/1.2.6 using Elastic Beanstalk and Node.js

The quick fix for this is for express/http server  to listen on process.env.PORT,  not on a hard coded port (e.g. 3000). This can be accomplished in express by using

var express = require(‘express’);
var app = express();
app.set(‘port’, process.env.PORT || 8081);


I could not find any options or commands to configure the port for node in Elastic Beanstalk. At the moment, Nginx on an aws 64 bit linux instance is connecting to port 8081 to the node instance. process.env.PORT is set to 8081. When Express was listening on 3000 the bad gateway error was showing up. The logs/events provided by EB were useful to get to the root of this.


  1. THANK YOU. This was driving me nuts. It’s confusing because their sample app has a hardcoded port 3000 (admittedly not using Express).

  2. RTimal

    October 11, 2013 at 10:07 pm

    Glad you found it helpful!

  3. Totally worked. Thanks man.

  4. Thank you.

Leave a Reply

Your email address will not be published.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 rajiev

Theme by Anders NorenUp ↑