Original address: https://www.nginx.com/resources/admin-guide/reverse-proxy/
Original title: Passing Request Headers
By default, NGINX will redefine two HTTP header fields, "Host" and "Connection" when proxying a request, and delete the header fields with empty values. "Host" will be set to the value of the $proxy_host
variable, and "Connection" will be set to close.
By default, NGINX redefines two header fields in proxied requests, “Host” and “Connection”, and eliminates the header fields whose values are empty strings. “Host” is set to the $proxy_host variable, and “Connection” is set to close .
To change these settings, including modifying other header fields, use the proxy_set_header
command. This directive can be used in location
or higher. Can also be in a specific server
context or in an http block, for example:
To change these setting, as well as modify other header fields, use the proxy_set_header directive. This directive can be specified in a location or higher. It can also be specified in a particular server context or in the http block. For example:
<code>location /some/path<span>/</span> { proxy_set_header Host <span>$host</span>; proxy_set_header X<span>-Real</span><span>-IP</span><span>$remote_addr</span>; proxy_pass http:<span>//localhost:8000;</span> }</code>
In this configuration, the "Host" field is set to the $host
variable.
In this configuration the “Host” field is set to the $host variable. To prevent a header field from being passed to the proxied server, just set it to the empty string.
<code>location /some/path<span>/</span> { proxy_set_header Accept<span>-Encoding</span><span>""</span>; proxy_pass http:<span>//localhost:8000;</span> }</code>