【发布时间】:2019-11-12 21:09:10
【问题描述】:
我想有一个基于我想从上游获取的标头的条件标头。 出于某种原因,它总是被翻译成默认值。
配置: 上游服务决定是否应该存在名为 x-no-iframe-protection 的标头。
主 nginx:
map $http_x_no_iframe_protection $x_frame_options {
yes "";
default "SAMEORIGIN";
}
server {
...
add_header X-Frame-Options $x_frame_options;
...
}
无论我尝试什么 - 我都会得到两个标题:
$ curl -v myhost
...
< x-no-iframe-protection: yes
< x-frame-options: SAMEORIGIN
...
澄清一下 - 我使用 x-no-iframe-protection 作为在特定情况下删除 x-frame-options 的技巧。我可以保留它(尽管一旦被 nginx 解析就不需要它了)
无论如何 - 我怎样才能让它被捕获以替换标题值?
【问题讨论】:
-
看here,我觉得这个问题和你的差不多。
-
$http_x_no_iframe_protection是请求标头的值,您可能会遇到$sent_http_x_no_iframe_protection是响应标头的值。 -
@RichardSmith - 成功了!请将您的评论表述为答案,以便我接受它
标签: nginx http-headers