Nginx Configuration redirecting to Node Application(Centos)

We may need some point of time to use reverse proxy server to redirect the requests to the application which may well called as a load balancer.

Nginx is one of the reverse proxy server and today I will explain how to use it to redirect to the node application running in a diffrent port.

Install the nginx 

Install the nginx either using yum (RHEL) or using apt-get install nginx in Ubuntu Operating System.

Configuration of Nginx

Centos:

In centos once we install the nginx we will have /etc/nginx/conf.d

i) Create a file virtual.conf in the conf.d directory

ii) Add the following in the directory

upstream app_cluster_1 {
server localhost:8080;
}

server {
listen 0.0.0.0:80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
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://app_cluster_1/;
proxy_redirect off;
proxy_cache anonymous;
}
}

ii)After this we need to change the default.conf.

Change the http default port from 80 to some port.

listen       80; to listen 8011;

iii) Restart the nginx server we will be getting the redirecting thing working

Ubuntu configuration will be posted in the next post…….;

Any queries feel free to ask me………..