原文網址:https://www.nginx.com/resources/admin-guide/reverse-proxy/
原文標題:Passing Request Headers
預設情況,NGINX在代理請求時會重新定義兩個HTTP頭字段,“Host”和“Connection”,並刪除值為空的頭部字段。 「Host」會被設定為 $proxy_host
變數的值,「Connection」被設定為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 is Connection to Connection” .
要改變這些設置,包括修改其他頭字段,使用proxy_set_header
指令。這個指令可以在location
或更高層使用。也可以在特定的server
上下文或在http區塊中,例如:
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 br.
$host變數。
In this configuration the “Host” field is set to the $host variable.
To prevent a header field from being passed to the proxied server, set it to an empty string as follows:
<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>