尝试使Nginx忽略并隐藏代理服务器的某些标题时遇到困难。
我希望Nginx隐藏和忽略“caching控制”和“服务器”头,但它不工作,我不知道为什么。
我的conf如下:
location / { proxy_pass http://111.131.50.42; proxy_hide_header Cache-Control; expires 60M; add_header Cache-Control "public"; proxy_ignore_headers Cache-Control; proxy_hide_header Cache-Control; access_log off; }
但即使如此,我仍然收到来源“caching控制”和“服务器”标题。
你知道我在做什么错吗?
PS我不能使用ngx_headers_more模块。 我无法将此模块添加到我们的Nginx安装中。
指令proxy_ignore_headers告诉nginx忽略导致特定内部行为的特殊标头的内容:
“X-Accel-Expires”,“Expires”,“Cache-Control”,“Set-Cookie”和“Vary”设置响应caching的参数。
“X-Accel-Redirect”执行内部redirect到指定的URI;
“X-Accel-Limit-Rate”设定向客户端发送回复的速率限制,
“X-Accel-Buffering”启用或禁用响应的缓冲;
“X-Accel-Charset”设置所需的响应字符集。
如果要隐藏上游服务器的标题,则需要使用proxy_hide_header 。 Server头不会传递给默认发送给客户端的响应,如Date , X-Pad和X-Accel-...头。
所以,这应该工作:
location / { access_log off; add_header Cache-Control "public"; proxy_pass http://111.131.50.42; proxy_hide_header Cache-Control; expires 60M; }
确保你没有使用caching数据的浏览器进行testing,请使用curl 。