John Datserakis

John Datserakis

How To Use A Reverse-Proxy On Your NGNIX Setup For Your Node Server

When running a Node application on your NGINX server you're going to want to run it through a reverse-proxy for security reasons.

I use Forge to manage a few of my servers. The way I make this change is to view the site's main info page and choose to edit the NGINX config.

1server { 2.. 3 # Comment out this code 4 # location / { 5 # try_files $uri $uri/ /index.php?\$query_string; 6 # } 7 8 location / { 9 proxy_pass http://$YOUR_IP:$APP_PORT; 10 proxy_http_version 1.1; 11 proxy_set_header Upgrade $http_upgrade; 12 proxy_set_header Connection 'upgrade'; 13 proxy_set_header Host $host; 14 proxy_set_header X-Real-IP $remote_addr; 15 proxy_cache_bypass $http_upgrade; 16 } 17.. 18}

You'll need to replace the $YOUR_IP and $APP_PORT variables with the IP Address of your server and port you're running your application on.

This will work just the same on NGNIX servers that are not associated with Forge. Just make sure to place it in the server block.

Now just make sure to restart NGINX

1sudo service nginx restart

And that should do it - now you'll be serving your application safely on your server!

For a more detailed walkthrough, check out this awesome walkthrough from Digital Ocean.