Welcome! Log In Create A New Profile

Advanced

Re: $upstream_http_NAME and $sent_http_NAME vars not available in certain scopes

Maxim Dounin
March 30, 2016 11:38AM
Hello!

On Wed, Mar 30, 2016 at 07:11:45AM -0400, neilstuartcraig wrote:

> Hi all
>
> I am developing a proxy service which uses NGINX to reverse proxy, kind of
> CDN-like but very specific to our needs. During this. I have hit an issue
> which I *think* is a bug but wanted to ask in case anyone can point to a
> solution or some reading I can do. The problem I have is this:
>
> $upstream_http_NAME and $sent_http_NAME variables seem to be
> unpopulated/blank at some points in my config when other embedded variables
> *are* populated. This is probably best illustrated via an example, so here's
> a simplified test case I created:

[...]

> # This does match - for obvious reasons
> if ($upstream_http_via ~* ".*") {
>
> # Problem: $upstream_http_via appears not to be populated at this
> point...
> set $via_comp "$upstream_http_via 1.y BLAH";
> more_set_headers "IF_VIA_COMP: Value is $via_comp";

[...]

> So my questions are:
> Can anyone see something I have done wrong?
> Is this expected behaviour (if yes, why? Seems strange some vars behave
> differently)
> Does anyone have a workaround or solution?

You are trying to use $upstream_http_via in the "if" and "set"
directives, this is wrong. The $upstream_http_via variable is
only available once a response is returned by an upstream server,
but the "if" and "set" directives are evaluated before the request
is sent to the upstream server, see here:

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

As far as I understand from your config, you want to add something
to the Via response header. Correct approach would be to only use
the header after the response is returned, e.g., in the
"add_header" directive. Try something like this:

map $upstream_http_via $is_via {
"" "";
default ", ";
}

server {
...

location / {
proxy_pass http://upstream;
proxy_hide_header Via;
add_header Via "$upstream_http_via$is_via1.1 foo"
}
}

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

$upstream_http_NAME and $sent_http_NAME vars not available in certain scopes

neilstuartcraig March 30, 2016 07:11AM

Re: $upstream_http_NAME and $sent_http_NAME vars not available in certain scopes

neilstuartcraig March 30, 2016 11:36AM

Re: $upstream_http_NAME and $sent_http_NAME vars not available in certain scopes

neilstuartcraig March 30, 2016 11:37AM

Re: $upstream_http_NAME and $sent_http_NAME vars not available in certain scopes

Maxim Dounin March 30, 2016 11:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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