I’m using the nginx X-Accel-Redirect feature where a proxied backend (A) can “internally redirect” nginx to reprocess a new URI (B) as if that were the one originally given by the client browser.
It works great in making request B (also proxied)and returning B’s resulting headers back to the client browser. So far so good.
But also I have some headers from A which I’d like to pass along too. In other words, merge a handful of headers from A in with the result from B.
How can I do this? I’ve tried
add_header X-My-Header $http_x_my_header;
$http_x_my_header variable is empty, presumably because the original request didn’t have it. I’ve also tried
$upstream_x_my_header but that’s empty too. I’ve tried things like
proxy_pass_header X-My-Header; but no.
After trial and error, I found the
$upstream_http_... headers to be working when first assigned to a variable;
So with your example that would become something like this;
set $my_header '$upstream_http_x_my_header'; add_header X-My-Header $my_header;
Answered by Koen. on December 27, 2020
According to nginx manual for proxy_set_header:
If value is empty string, then header will not be sent to upstream.
proxy_set_header X-My-Header "OK" or perhaps a variable you'd like to use as value. That should pass it to the proxy as well as the user.
Answered by Sašo on December 27, 2020
1 Asked on December 22, 2020 by giovanni-tirloni
1 Asked on December 21, 2020 by user594268
1 Asked on December 21, 2020 by hazaki
0 Asked on December 21, 2020 by paula-silva
0 Asked on December 21, 2020 by soupdiver
1 Asked on December 20, 2020 by sam1975
1 Asked on December 20, 2020 by anon-ymous
1 Asked on December 20, 2020 by matthieu-napoli
1 Asked on December 20, 2020 by rosengrenen
0 Asked on December 20, 2020 by manifestor
2 Asked on December 18, 2020 by estege
1 Asked on December 18, 2020 by drteeth
1 Asked on December 18, 2020 by richb
1 Asked on December 17, 2020 by chobo2
0 Asked on December 17, 2020 by geofflittle
2 Asked on December 17, 2020 by numemiie
0 Asked on December 16, 2020 by nerigal
1 Asked on December 16, 2020 by googlebot
1 Asked on December 15, 2020 by manny0606
Get help from others!