文档说明了这一点:
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 X-Frame-Options SAMEORIGIN;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
location ~ ^/img/(.*)\.(png|jpg|jpeg|gif|bmp)${
expires 1w;
add_header Cache-Control public;
}
但这将使我失去在块外宣布的所有标题.显然,唯一的方法是在每个位置块上复制这些标头,例如:
add_header X-Frame-Options SAMEORIGIN;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
location ~ ^/img/(.*)\.(png|jpg|jpeg|gif|bmp)${
expires 1w;
add_header Cache-Control public;
add_header X-Frame-Options SAMEORIGIN;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
}
似乎不对.有任何想法吗?
最佳答案
你是在ngx_headers_more模块之后:
https://www.nginx.com/resources/wiki/modules/headers_more/
原文链接:https://www.f2er.com/nginx/435467.htmlhttps://www.nginx.com/resources/wiki/modules/headers_more/
是的,add_header的行为真的很烦人:)