nginx add_header在我的某个位置无效

前端之家收集整理的这篇文章主要介绍了nginx add_header在我的某个位置无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

原文链接:https://www.f2er.com/nginx/435441.html

猜你在找的Nginx相关文章