Nginx reverse proxy to nodejs app - domain root location redirects browser back to server IP

Posted April 6, 2019 14.4k views
NginxNode.jsUbuntu 18.04

I have a client with an existing domain name which cannot be pointed to my server just yet.

So in the meanwhile I’ve added my node app and configuring the reverse proxy. This is what I’ve done:

  1. Added domain entries to my local machine’s hosts file:

  2. on my droplet’s hosts file, I did the same:

  3. My nginx reverse proxy setup. This is my /etc/nginx/sites-available/default file:

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.php index.js index.html index.htm index.nginx-debian.html;
        location / {
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

Now what happens if I visit any subpath, like, everything works fine.

But, when I visit root - contents are loaded fine, but the address in my browser address bar changes to .

Looking at my network tab, I see that initiator is, but in the request headers host is actually (not

How can I fix this?

I followed this guide to set up the reverse proxy:

The only prerequisite I have not done is SSL - again because I cannot point this domain name to my server yet. I don’t think that should have anything to do with it though.

1 comment
Submit an answer

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