Monthly Archives: December 2016

Using NGINX for Proxy Pass

Lets say I have two servers running on my laptop
1. http://localhost:3000 – This is the UI
2. http://localhost:4000 – This is the web services API

So now I need to setup something like this:
1. http://localhost/ – This should point to UI
2. http://localhost/api/ – This should point to web services API

To set this up I have used NGINX and added this section in the “server” section of the nginx.conf file. On my Mac system this file is located at: /usr/local/etc/nginx/nginx.conf

location /api/ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:4000/;
}

location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3000/;
}

To reload NGINX I use the “-s reload” parameter for nginx. On my Mac I execute this command:
/usr/local/Cellar/nginx/1.10.0/bin/nginx -s reload