Welcome! Log In Create A New Profile

Advanced

Re: How to upstream request set header based on SSI variable?

Jan Algermissen
December 08, 2016 09:14AM
On 8 Dec 2016, at 14:47, Maxim Dounin wrote:

> 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.

Yes, I suspected that.

>
> 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;
> }

Clever, thanks - works just fine.

Jan




> --
> Maxim Dounin
> http://nginx.org/
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to upstream request set header based on SSI variable?

Jan Algermissen December 07, 2016 03:04PM

Re: How to upstream request set header based on SSI variable?

Maxim Dounin December 08, 2016 08:48AM

Re: How to upstream request set header based on SSI variable?

Jan Algermissen December 08, 2016 09:14AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 194
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