加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx add_header在我的某个位置无效

发布时间:2020-05-27 07:50:25 所属栏目:Nginx 来源:互联网
导读:我使用nginx 1.10.1配置与此类似:server { (...) add_header Header1 value; (...) # in this location above add_header directive works location / { uwsgi_pass

我使用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;
    }
}

..所以我的问题是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”;.

(编辑:安卓应用网)

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

    推荐文章
      热点阅读