Cannot connect to node-app externally

Posted May 18, 2017 8.3k views
Node.jsUbuntu 16.04

For some odd reason, I cannot connect to my node-app externally, I can’t figure why, please send help! :D

root@gitty:~/ node server/ &
[1] 6585
root@gitty:~/ nListening on { address: '', family: 'IPv4', port: 3000 }
root@gitty:~/ netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0    *               LISTEN      3194/nginx -g daemo
tcp        0      0    *               LISTEN      1398/sshd
tcp        0      0  *               LISTEN      6585/node

Ps. Nginx works, but node doesn’t :c

Sincerely, Mads Cordes

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.

Submit an Answer
2 answers


Posting this as a separate reply since it’ll be a little lengthy :-).

The default server block for NGINX will be located at:


The above file, with NGINX running, is why you’ll see some sort of response to incoming requests after pointing your domain to the IP of the Droplet.

You’ll need to modify that file to suit your specific needs and proxy requests to your NodeJS app. To start, I’d recommend wiping that file clean.

To do that, we can run:

truncate -s 0 /etc/nginx/sites-available/default

That’ll result in an empty file we can now setup to respond to requests for your application. So let’s go ahead and edit it.

nano /etc/nginx/sites-available/default

Within that file, paste in:

upstream @backend {

    listen 80;
    listen [::]:80;

    location /
        proxy_pass http://@backend;

        proxy_buffers 16 32k;
        proxy_buffer_size 64k;
        proxy_busy_buffers_size 128k;
        proxy_cache_bypass $http_pragma $http_authorization;
        proxy_connect_timeout 59s;
        proxy_hide_header X-Powered-By;
        proxy_http_version 1.1;
        proxy_ignore_headers Cache-Control Expires;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
        proxy_no_cache $http_pragma $http_authorization;
        proxy_pass_header Set-Cookie;
        proxy_read_timeout 600;
        proxy_redirect off;
        proxy_send_timeout 600;
        proxy_temp_file_write_size 64k;
        proxy_set_header Accept-Encoding '';
        proxy_set_header Cookie $http_cookie;
        proxy_set_header Host $host;
        proxy_set_header Proxy '';
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Original-Request $request_uri;

You’ll need to modify:


…and replace with your actual domain name.

Once you’ve done that, save the file and restart NGINX using:

service nginx restart

That should get things working for you without having to attach the port to the URL.


We’d need to take a look at the server block you configured for NGINX and your NodeJS app.

Without a properly configured server block that proxies requests on port 80 to 3000, the only way to access your application from the browser will be by appending the port to the end of the URL or IP.

  • Well, I just connected a domain to my server, and that works? I’m so, so confused! Though, I still can’t connect to my server using the ip in a browser..?

    • @Mobilpadde

      Installing NGINX will allow your domain to resolve to the server since it’s a web server, but you need to further configure it to work with NodeJS as, by default, NGINX only listens on ports 80 and 443 – the standard web ports for HTTP and HTTPS. It has no knowledge of NodeJS or your application until you configure it to proxy requests to it.

      NGINX will handling incoming requests once it’s active and the service is running, though without further configuration, the only thing it’ll serve is the standard Welcome to NGINX message, or similar.

      • But thing is, that it does work with my domain, but I cannot connect to the ip on the given port, which is what I do not understand.

        • @Mobilpadde

          See my response below. Ideally, you should run the application using either:




          This is especially the case if you’re going to use NGINX as the purpose of NGINX in such a scenario is to proxy requests on Port 80 to your application on port 3000.

          Without NGINX, or a web server to proxy in general, the only means of access for your application would be IP:PORT.

          If you’re not able to access it using the IP:PORT while using, then it may be due to the application, or the fact that you’re pushing it to the background using the &. Ideally, you’d use PM2 or another process manager to keep the application running as using & can be unreliable.