I know I'm close but I can't seem to connect my node.js app to my NGINX reverse proxy. My node app works locally and my config file tests ok. It doesn't connect after it's been uploaded to Digital Ocean.

The error is 502 Bad Gateway.

Something is missing and after a couple of hours of googling and testing I still can't find the problem. Thanks so much for any help in advance!

These are the relevant lines from my nginx.conf file.

 server {
        listen        80;
        listen        [::]:80;
        server_name   myDomainName.com;
        root          /www/html;

        location / {
             index       index.html;

        location /proxytest {
            proxy_pass "http://www.myDomainName.com:8080";


This is my node.js test app.

const express = require('express');

const app = express();

app.get('/', (request, response) => {
    response.send('Hello World!');

app.listen(8080, () => {
    console.log('Server is up on port 8080');

If this is all running a single instance, then typically Nginx wants to talk to a local nodejs service running on port 8080, and so localhost would be more usual than www.myDomainName.com

This would normally be something like

 location /proxytest {
            proxy_pass http://localhost:8080;

Whatever you set the proxy_pass value to, you should check that address is available from the nginx box command line.

# curl -I  http://localhost:8080
HTTP/1.1 200 OK
X-Powered-By: Express
Date: Tue, 06 Feb 2018 02:23:35 GMT
Connection: keep-alive

Also you can check the error log on nginx to see if it reported anything funny.

vi /var/log/nginx/error.log

Other things to try

If you are on an selinux distribution (CentOS, Fedora, RHEL...) try disabling selinux and try the request again

 # setenforce Permissive
 setenforce: SELinux is disabled
| improve this answer | |
  • Thanks so much Tom! I used curl -I http://localhost:8080 and it returned HTTP/1.1 404 Not Found. So for my next step I typed ps -aef and my node server was running. I checked SELinux and my server is set to httpd_sys_content_t just like the rest of the files in my folder. DAC looks fine too. If the server returns 404 what should I check? – DR01D Feb 6 '18 at 16:29
  • are you sure its the node app listening on 8080 and not something else? I started that app on my box.. $ node ~/Downloads/test1.js \n Server is up on port 8080 – Tom H Feb 6 '18 at 16:41
  • and the output is $ curl -I http://localhost:8080 HTTP/1.1 200 OK X-Powered-By: Express Content-Type: text/html; charset=utf-8 Content-Length: 12 ETag: W/"c-Lve95gjOVATpfV8EL5X4nxwjKHE" Date: Tue, 06 Feb 2018 16:41:08 GMT Connection: keep-alive – Tom H Feb 6 '18 at 16:42
  • I rebooted the server. Oddly enough when I used ps -aef | grep 8080 it returns first 10388 10343 0 09:54 pts/0 00:00:00 grep --color=auto 8080 But server.js is running. – DR01D Feb 6 '18 at 16:55
  • ps -aef | grep node returns first 10381 10343 0 09:54 pts/0 00:00:00 node server.js and first 10391 10343 0 09:58 pts/0 00:00:00 grep --color=auto node – DR01D Feb 6 '18 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.