我很难理解nginx何时覆盖我的add_header指令。
我有以下内容:
include /etc/nginx/vhost.d/ihc.example.com;
location = /auth {
proxy_pass http://sso.example.com/auth/login;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
auth_request /auth;
auth_request_set $saved_set_cookie $upstream_http_set_cookie;
add_header Set-Cookie $saved_set_cookie; #I don't see this header in the response
proxy_pass http://ihc.example.com;
include /etc/nginx/vhost.d/ihc.example.com_location;
}
我遇到的问题是auth_request_set $saved_set_cookie $upstream_http_set_cookie;
Cookie没有出现在回复中。
现在,如果我删除include /etc/nginx/vhost.d/ihc.example.com_location;
行,它会出现,但是这个文件包含一个共享的CORS修复程序,我真的非常希望保留:
if ($cors = 'trueGET') {
add_header 'Access-Control-Allow-Origin' $http_origin; #I see this header in the response
[...]
如何在不必在每个位置重复CORS标头的情况下实现这两个目标?是什么导致这被覆盖?当我阅读文档时,location
应该覆盖server
,但在这种情况下,导致这个新"范围的原因是什么?#/ p>
答案 0 :(得分:1)