# Re: Handler invokation after upstream server being picked

**URL:** <https://www.ruby-forum.com/t/re-handler-invokation-after-upstream-server-being-picked/237417>\
**Category:** NGINX\
**Created:** [November 12, 2013, 3:29pm UTC](https://www.ruby-forum.com/t/re-handler-invokation-after-upstream-server-being-picked/237417 "2013-11-12T15:29:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [November 12, 2013, 3:29pm UTC](https://www.ruby-forum.com/t/re-handler-invokation-after-upstream-server-being-picked/237417/1 "2013-11-12T15:29:41Z")

</div>

Maxim,

a while ago you replied to my question below.

Since yesterday I am trying to get hold of the proxy\_host variable set  
by the proxy module but without success, maybe you can help a little  
with the code.

From the source I understood that the proxy module sets the proxy\_host  
var during NGINX startup. I guess, that happens on a per-location basis,  
depending on encountering a proxy\_pass directive.

Correct?

I should then be able to access the proxy\_host variable during the  
authentication phase (this is where my module sits).

Correct?

To get hold of it, I try to find the index of the proxy\_host var in my  
location config merge handler:

```
var.data = (unsigned char*)"proxy_host";
var.len = 10;
child->proxy_host_var_index = ngx_http_get_variable_index(cf, &var);

if (child->proxy_host_var_index == NGX_ERROR) { /* NOT FOUND, TRY 

```

TO INHERIT \*/  
child-\>proxy\_host\_var\_index = parent-\>proxy\_host\_var\_index;  
return NGX\_CONF\_OK;  
}

/\* FOUND - This loca config has its own proxy\_pass configuration \*/

In my handler, I then do this:

ngx\_http\_variable\_value\_t \*value;  
…  
value = ngx\_http\_get\_indexed\_variable(r,  
conf-\>proxy\_host\_var\_index);

Does that make sense? I does not work for me, unfortunately.

(The log module does see the proxy\_host variable and logs the expected  
value for it.

Jan

---

<div class="post-metadata">

**Author:** ![jandot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jandot](https://www.ruby-forum.com/u/jandot)\
**Post date:** [November 12, 2013, 4:38pm UTC](https://www.ruby-forum.com/t/re-handler-invokation-after-upstream-server-being-picked/237417/2 "2013-11-12T16:38:02Z")

</div>

Hello!

On Tue, Nov 12, 2013 at 03:28:48PM +0100, Jan A. wrote:

> per-location basis, depending on encountering a proxy\_pass  
> directive.
> 
> Correct?

Not exactly. Variables only exists during requests processing.  
That is, the $proxy\_host variable isn’t set during nginx startup,  
but instead its value becomes known when proxy module starts  
working with a request.

> I should then be able to access the proxy\_host variable during  
> the authentication phase (this is where my module sits).
> 
> Correct?

No, see above. The $proxy\_host variable value is not known till  
proxy started to work (and, if variables are used in proxy\_pass,  
evaluated its parameter).

> ```
> }
> 
> ```
> 
> (The log module does see the proxy\_host variable and logs the expected value for  
> it.

See above for explanation why it doesn’t work for you. Looking  
into src/http/modules/ngx\_http\_proxy\_module.c might be helpful,  
too.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)
