How do you set important proxy headers like X-Forwarded-For and Host?
⚡
Quick Answer
Set proxy_set_header for Host and X-Forwarded-* so backends see the original client and host.
Detailed Answer
Behind a proxy, backends otherwise see NGINX's IP and the internal host. proxy_set_header Host $host and X-Forwarded-For $proxy_add_x_forwarded_for preserve the client's host and IP chain; X-Forwarded-Proto conveys the original scheme for correct redirects and cookies.
💡
Interview Tip
Forgetting these breaks client IP logging and HTTPS redirects.
nginxheadersproxy