How to upstream request set header based on SSI variable?
Jan Algermissen
algermissen1971 at icloud.com
Thu Dec 8 14:12:55 UTC 2016
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 at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
More information about the nginx
mailing list