proxy - IP based load balance in nginx - Ask Ubuntu
i have 2 backend server running on 192.168.0.101:8080 , 192.168.0.102:8080.
i have nginx running on 192.168.0.111:80, want force nginx reverse traffic in specific backend srever ip.
geo $upstream { 192.168.0.150 backend-1; 192.168.0.250 backend-2; default backend-1; } upstream backend-1 { ip_hash; server 192.168.0.101:8080; } upstream backend-2 { ip_hash; server 192.168.0.102:8080; } server { listen 80; location / { proxy_pass http://$upstream; proxy_redirect off; proxy_set_header host $host; proxy_set_header x-forwarded-host $host; proxy_set_header x-forwarded-server $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } }
i confused configuration. gonna work meant ? every request 192.168.0.150 go backend-1(192.168.0.102:8080) ? , 192.168.0.250 in backend-2 ?
question: not redirecting based on ip addresses. why ?
the working config:
geo $upstream { default backend-1; 192.168.0.150 backend-1; 192.168.0.250 backend-2; } upstream backend-1 { server 192.168.0.101:8080; } upstream backend-2 { server 192.168.0.102:8080; } server { listen 80; location / { proxy_pass http://$upstream; proxy_redirect off; proxy_set_header host $host; proxy_set_header x-forwarded-host $host; proxy_set_header x-forwarded-server $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } }
Comments
Post a Comment