加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 运营中心 > Nginx > 正文

如何避免在nginx中重复add_header指令?

发布时间:2021-02-21 03:29:36 所属栏目:Nginx 来源:互联网
导读:文档说明了这一点: 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

文档说明了这一点:

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/

是的,add_header的行为真的很烦人:)

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读