How to use Nginx as reverse proxy for Node apps?

First we need to do followings
1. Create Node App
2. Create Nginx server block
3. Update hosts file
4. Restart Nginx

1. Create Node App
Already I have node app that is running on http://localhost://3000
So start with second point.
2. Create nginx server block
Run following command on terminal

sudo nano /etc/nginx/sites-available/{}

And put following contents

server {
    listen 80;


    location / {
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $http_host; 
        proxy_set_header X-NginX-Proxy true; 

        proxy_pass http://localhost:3000/; 
        proxy_redirect off; 

        # Socket.IO Support 
        proxy_http_version 1.1; 
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade"; 

and press control+o and then control+x to save & close file
Now run following command on terminal to create symlink

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/ 

3. Update hosts file

sudo nano /etc/hosts

put following line at bottom of this file
and press control+o and then control+x to save & close file
4. Restart Nginx

sudo service nginx restart

About Jaffar Hussain

Jaffar Hussain is an Enthusiastic Software Engineer having vast experience in Zend, SugarCRM, Laravel php frameworks and good command on databases Mysql, MongoDB, SqlServer 2008.