Nginx:访问镜像块中的$upstream_http header

问题描述 投票:0回答:1

我的镜像工作得很好,并且我在镜像服务器中正确获取了原始请求正文。

但是,我需要从原始上游访问名为

Location
的响应标头并将其转发到我的镜像。通常,将使用以下变量访问来自上游的响应标头:
$upstream_http_<*header name*>
,在我的例子中为
$upstream_http_location

但是我想在我的镜像中访问它,以便我可以将响应标头从上游转发到我的镜像。

我该怎么做?这是我当前的配置,但它不起作用,而且我在镜子中看不到标题

DAV-response
。是否有另一种方法可以访问镜像块中的所有
$upstream_http
标头?

我在 nginx 中有以下请求镜像设置:

location /ops/opendata/DataAccessViewer/ {
  mirror /davmirror;
  proxy_pass  https://<upstream>/;
  proxy_redirect  https://<upstream>/ /; 
}

location /davmirror {
    internal;
    proxy_pass https://<mirror>;
    proxy_set_header DAV-Original-URI $request_uri;  # <<<<-- works!
    proxy_set_header DAV-tier internals; # <<<<-- works!
    proxy_set_header DAV-response $upstream_http_location; # <<<-- DOESNT WORK!
}

更新

欢迎使用 nginx 实现这一目标的替代解决方案。我知道其他非 nginx 解决方法,事实上目前正在使用它们作为后备。理想情况下,我们希望这是 nginx 解决方案。

更新 这个问题似乎表明nginx在解析镜像之前实际上正在等待上游响应?

nginx nginx-reverse-proxy nginx-location
1个回答
0
投票

如果您在访问镜像块中的

Location
标头时遇到问题,可能是因为该标头未包含在上游服务器的响应中,要进行检查,您可以使用
curl
或浏览器开发人员等工具用于查看响应标头的工具,但如果存在
Location
标头,则您设置镜像块的方式可能存在问题。

此外,您可以尝试使用

$upstream_http_
,而不是使用
$sent_http_
,它也具有来自上游服务器的响应标头。

类似这样的:

location /ops/opendata/DataAccessViewer/ {
  mirror /davmirror;
  proxy_pass  https://<upstream>/;
  proxy_redirect  https://<upstream>/ /; 
}

location /davmirror {
    internal;
    proxy_pass https://<mirror>;
    proxy_set_header DAV-Original-URI $request_uri;
    proxy_set_header DAV-tier internals;
    proxy_set_header DAV-response $sent_http_location;
}
© www.soinside.com 2019 - 2024. All rights reserved.