502 Bad Gateway remains! Meteor.js NGINX


I have been researching and trying out many different ways to kill my 502 Bad Gateway but to no success!

Domain Registrar: GoDaddy. My normal home web-page’s domain is which forwards to an instapage website, but I have a subdomain to redirect (301) to my DO droplet. Added an A record for login that points to the DO IP.

Deploying Meteor I follow the this guide where I run “sudo npm install” while being the myapp user.

My /etc/nginx/sites-available/myapp.conf file:

server_tokens off;
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
server {
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html; # root is irrelevant
    index index.html index.htm; # this is also irrelevant

    location / {
        rewrite     ^ https://$server_name$request_uri? permanent;
server {
    listen 443 ssl spdy;
    root html;
    index index.html;

    ssl_certificate /etc/nginx/ssl/server.pem;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    ssl_stapling on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 5m;

    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    add_header Strict-Transport-Security "max-age=31536000;";
    if ($http_user_agent ~ "MSIE" ) {
        return 303;
    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; # allow websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
        if ($uri != '/') {
            expires 30d;

My /etc/init/myapp.conf file:

description "Meteor.js (NodeJS) application"
author "Daniel Speichert <>"
start on started mongodb and runlevel [2345]
stop on shutdown
respawn limit 10 5
setuid myapp
setgid myapp

    export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
    export PWD=/home/myapp
    export HOME=/home/myapp
    export BIND_IP=
    export PORT=8080
    export MONGO_URL=mongodb://localhost:27017/myapp
    export ROOT_URL=
    exec node /home/myapp/bundle/main.js >> /home/myapp/myapp.log
end script


  • My DO is Ubuntu 14.04 x64
  • the names mydomain and myapp are not the same if that matters
  • I set-up SSL exactly like this:
  • When I run “start myapp” it says “myapp start/running, process 12218” and when I type “status myapp” it then shows “myapp stop/waiting”.
  • NGINX is running.
  • /home/myapp/myapp.log is empty so somehow the Meteor app doesn’t see any errors.
  • “nginx -t” returns all OK except SSL stapling warning
  • My NGINX error log says 2016/05/04 00:30:42 [error] 18144#0: *28 connect() failed (111: Connection refused) while connecting to upstream, client: <IP ADDRESS>, server:, request: “GET /favicon.ico HTTP/1.1”, upstream: “”, host: “”, referrer: “
  • My code runs on my localhost just fine on my dev laptop (Mac OS).
  • I cannot access it on <IP ADDRESS>:8080 so it seems it just can’t reach Meteor on the server.
  • “sudo netstat -plutn” output: tcp 0 0* LISTEN 12209/nginx
    tcp 0 0* LISTEN 2880/mongod
    tcp 0 0* LISTEN 1103/sshd
    tcp 0 0* LISTEN 12209/nginx
    tcp 0 0* LISTEN 2880/mongod
    tcp6 0 0 :::80 :::* LISTEN 12209/nginx
    tcp6 0 0 :::22 :::* LISTEN 1103/sshd

Anybody any idea why there’s still a 502 Bad Gateway issue?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I have the same problem :/

I seem to have the same issue.