Nginx Config for load balancing ( using UPStream module)

by Balasundaram

Upstream module in nginx gives the way for load balancing.

The below is the nginx config for load balancing two redis slaves

upstream app_cluster_1 {
server 127.0.0.1:6379;
server 127.0.0.1:6380;
}

server {
listen 0.0.0.0:8001;
server_name nodetest.local nodetest;
access_log /var/log/nginx/nodetest.log;
error_log /var/log/nginx/nodetesterrot.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;
}

}

Advertisements