
文件是這樣說的:
當且僅噹噹前層級上沒有定義 add_header 指令時,這些指令才會從上一層繼承。
我的問題是我有幾個location
想要快取的區塊,如下所示:
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;";
}
似乎不對。有任何想法嗎?
答案1
您正在尋找 ngx_headers_more 模組: https://www.nginx.com/resources/wiki/modules/headers_more/
是的,add_header 的行為確實令人惱火:)