How to upstream request set header based on SSI variable?
Maxim Dounin
mdounin at mdounin.ru
Thu Dec 8 13:47:18 UTC 2016
Hello!
On Wed, Dec 07, 2016 at 09:02:39PM +0100, Jan Algermissen wrote:
> Hi,
>
> I have setup SSI to include responses from upstream services.
>
> I am trying to find a way to set additional headers for these upstream
> requests based on a variable set in the SSI page but I am not sure if
> that even works at all.
>
> Does someone know *if* this is doable and if so, how?
>
>
> In config I have
>
> server {
> set $etag "xxxxx";
>
> location /up1/ {
> proxy_set_header If-Match $etag;
> proxy_pass http://upstream1/up1/;
> }
> }
>
>
>
> <!--# set var="etag" value="123456" -->
> <!--# include virtual="/up1/this/is/requested/from/upstream" -->
>
>
> This sends an
>
> If-Match: xxxxx
>
> header to the upstream, but what I want to achieve is to send the
> "123456" instead.
>
> I'd also be glad for suggestions what I might try to get this to work.
The approach you are using won't work, as variables set via the
SSI "set" command are local to SSI and can be only accessed in
SSI.
An alternative solution would be to use appropriate value in URI
of the "include" command, with appropriate URI change later:
<!--# include virtual="/up1/foo?12345" -->
location /up1/ {
set $etag $args;
set $args "";
proxy_set_header If-Match $etag;
proxy_pass http://upstream1;
}
--
Maxim Dounin
http://nginx.org/
More information about the nginx
mailing list