首页 > 解决方案 > 位置块上的 nginx add_headers 被删除

问题描述

我用谷歌搜索但没有找到解决我的问题的方法:

add_header X-debug-message "debug-msg 1" always;
location ^~ /backend {
   try_files $uri $uri/ /back.php?$args;
   add_header X-debug-message "debug-msg 2" always;
}
add_header X-debug-message "debug-msg 3" always;

所以,对于/backend位置,我只能看到"debug-msg 1""debug-msg 3"标题。为什么我看不到"debug-msg 2"?我确定/backend输入了位置块。

标签: nginxnginx-location

解决方案


是的。它的行为记录在案

可能有几个 add_header 指令。当且仅当当前级别上没有定义 add_header 指令时,这些指令才从上一层继承

你应该看看 more_set_headers 作为替代品


推荐阅读