nginx 设置代理的header
要在nginx中设置代理的header,可以使用proxy_set_header指令。该指令用于设置在代理请求中发送的header。
以下是一个示例配置,展示了如何设置代理的header:
location / {
proxy_pass http://backend_server;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header User-Agent $http_user_agent;
}
在上面的示例中,proxy_set_header指令用于设置三个header:X-Forwarded-For、Host和User-Agent。你可以根据需要添加或修改其他header。
注意事项:
- 在设置header时,可以使用nginx预定义的变量(如$proxy_add_x_forwarded_for、$host等)或自定义变量。
- 当使用proxy_set_header指令时,默认情况下nginx会保留原始请求中的header。如果不想保留原始header,可以使用proxy_set_header指令的第三个参数,将其设置为off。
- 如果要删除某个header,可以使用proxy_hide_header指令。
更多关于proxy_set_header和相关指令的详细信息,请参考nginx官方文档
原文地址: https://www.cveoy.top/t/topic/iqJU 著作权归作者所有。请勿转载和采集!