我使用nginx 1.10.1,configuration如下:
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; } }
..所以我的问题是,Header1设置为第一个位置处理的请求,但不是第二个。
为什么?
我已经阅读了add_header文档,并知道它默认情况下只适用于“积极”的返回代码,但204是其中之一(我已经testing了代码更改为200,404,并没有帮助)。
(我也试图添加到我的add_header Header1 ...但是这是一个相当绝望的尝试,因为它不应该帮助 – 而事实并非如此。)
该文件指出:
当且仅当在当前级别上没有定义add_header指令时,这些指令才从前一级inheritance
add_header Cache-Control "public";的存在 阻止该块inheritanceadd_header Header1 "value"; 。