允许重新定义传递给代理服务器的请求正文。可以包含文本、变量及其组合。
语法: proxy_set_header field value;
违约:
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
上下文: http, ,serverlocation
允许将字段重新定义或追加到传递给代理服务器的请求标头。可以包含文本、变量及其组合。当且仅当当前级别上未定义指令时,这些指令才会从以前的配置级别继承。默认情况下,仅重定义两个字段:valueproxy_set_header
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
如果启用了缓存,则原始请求中的标头字段“If-Modified-Since”、“If-Unmodified-Since”、“If-None-Match”、“If-Match”、“Range”和“If-Range”不会传递到代理服务器。
可以按如下方式传递未更改的“Host”请求标头字段:
proxy_set_header Host $http_host;
但是,如果客户端请求标头中不存在此字段,则不会传递任何内容。在这种情况下,最好使用变量 - 其值等于“Host”请求标头字段中的服务器名称,如果此字段不存在,则等于主服务器名称:$host
proxy_set_header Host $host;
此外,服务器名称可以与代理服务器的端口一起传递:
proxy_set_header Host $host:$proxy_port;
如果标头字段的值为空字符串,则此字段不会传递到代理服务器:
proxy_set_header Accept-Encoding "";