NGINX指令add_headers的问题

时间:2020-05-27 14:33:31

标签: php nginx

我正在尝试根据发行量设置自定义内容安全策略,但标题未显示在浏览器中。

这是我最初尝试的方法(无效)。

location / {
    add_header "Content-Security-Policy-Report-Only" "default-src 'self';";
    try_files $uri $uri/ /index.php$is_args$args;
}

location /myfolder/ {
    add_header "Content-Security-Policy-Report-Only" "default-src 'self' data:;";
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php-fpm.sock;
}

还尝试在php位置内添加add_header指令(以及许多其他组合),但是我找不到能解决我问题的方法。

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php-fpm.sock;

    location / {
        add_header "Content-Security-Policy-Report-Only" "default-src 'self';";
    }

    location /myfolder/ {
        add_header "Content-Security-Policy-Report-Only" "default-src 'self' data:;";
    }
}

仅需一个add_header,该问题就很容易解决,因为它可以包含在php块中(或在其中的三个中),但是当我遇到这种情况时,我找不到解决方案标头必须按目录设置。

还有其他人有这个问题吗?任何帮助将不胜感激。

0 个答案:

没有答案