Welcome! Log In Create A New Profile

Advanced

How to access $upstream_http header in the mirror block

August 25, 2023 11:46PM
This is a cross post from the following Stackoverflow question. Please feel free to reply there as well, since I have already spent on a bounty and I would rather someone get it :)

https://stackoverflow.com/questions/76950023/nginx-access-upstream-http-header-in-the-mirror-block



My mirroring works just fine, and I am correctly getting the original request body in the mirror server.

However I need to access a response header called `Location` from the original upstream and forward it to my mirror. Typically the response header from upstream will be accessed using this variable: `$upstream_http_<*header name*>`, in my case `$upstream_http_location`.

However I want to access this in my mirror so I can forward the response header from my upstream to my mirror.

How do I do this? Here's my current configuration, but it doesn't work and I don't see the header `DAV-response` in my mirror. Is there another way to access all `$upstream_http` headers in the mirror block?


I have the following request mirroring setup in 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!
}
```

> Update

Open to alternative solutions to achieve this using nginx. I am aware of other non-nginx workarounds and in-fact using those as fallbacks at the moment. Ideally we would want this to be nginx solution.

> Update
This [question][1] seems to suggest that nginx is actually waiting on upstream response before resolving mirror?


[1]: https://stackoverflow.com/questions/51644141/how-to-make-nginx-mirror-module-not-wait-for-response
Subject Author Posted

How to access $upstream_http header in the mirror block

shaunakv1 August 25, 2023 11:46PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 267
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready