X-Forwarded-For header sent to the upstream server if the client IP is 192.168.1.10 and the original X-Forwarded-For header was 10.0.0.1?proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
The variable $proxy_add_x_forwarded_for appends the client IP to the existing X-Forwarded-For header, separated by a comma. So the original header 10.0.0.1 becomes 10.0.0.1, 192.168.1.10.
Host header important in Nginx proxying?Host header using proxy_set_header Host $host;?The Host header tells the upstream server which hostname the client requested. This is critical for servers hosting multiple sites (virtual hosts) to respond correctly.
proxy_set_header X-Real-IP $remote_addr;But the upstream server logs show the proxy server's IP instead of the client IP. What is the most likely cause?
Nginx sets the X-Real-IP header correctly, but the upstream server must be configured to read this header for logging. Otherwise, it logs the IP of the proxy connection.
The variable $proxy_add_x_forwarded_for appends the current client IP to the existing X-Forwarded-For header, preserving the full chain.
First, the load balancer must pass the client IP in headers. Then Nginx adds or appends headers before proxying. The upstream server must trust and extract the IP from headers. Finally, verify logs.