Nginx load balancing and maintaining URLs
Posted
by Steve Klabnik
on Server Fault
See other posts from Server Fault
or by Steve Klabnik
Published on 2010-01-27T20:44:36Z
Indexed on
2010/04/15
6:03 UTC
Read the original article
Hit count: 235
nginx
|load-balancing
I'm trying to use nginx as a load balancer, and it's working great. One problem, though.
The load balancing box is at 123.123.123.123, and the backend box is 456.456.456.456. So I have this config:
upstream backend {
server 456.456.456.456;
}
server {
listen 80;
server_name 123.123.123.123;
access_log off;
error_log off;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
}
}
This works great. I hit 123.123.123.123 in my browser, and the page comes up. But now the URL in the browser says http://456.456.456.456.
Do I need to use a rewrite rule or something to keep the url correct? I don't want it to be different when going to different backed servers. None of the tutorials I've read have mentioned anything about this.
© Server Fault or respective owner