我使用Nginx 1.10.1配置与此类似:
server { (...) add_header Header1 "value"; (...) # in this location above add_header directive works location / { uwsgi_pass unix:/var/run/some.sock; (...) } # ..and it this one it doesn't! location ~* (^/$|favicon.ico|robots.txt) { return 204; expires 24h; add_header Cache-Control "public"; etag on; } }
@H_301_8@..所以我的问题是Header1是为第一个位置处理的请求设置的,而不是第二个位置处理的请求.
为什么?
我已经阅读了add_header文档,并且知道它默认只用于“肯定”返回代码,但204是其中之一(我实际上已经测试过将代码更改为200,404并没有帮助).
(我也试着总是添加到我的add_header Header1 ……但这是一个相当绝望的尝试,因为它不应该帮助 – 而且它没有.)
最佳答案
The documentation州:
These directives are inherited from the prevIoUs level if and only if
there are no add_header directives defined on the current level
add_header Cache-Control“public”的存在;防止该块继承add_header Header1“value”;.