Variable for the real port of a proxy?

Mark Reginald James mrj at bigpond.net.au
Wed Oct 29 08:22:27 MSK 2008


Mark Reginald James wrote:
> Hi,
> 
> Is there any way to set a header that identifies the real
> port of the proxy that's handing a request? That is, if I
> have a round-robin proxy-set, a request forwarded to the
> proxy at port 8000 will have the header "X-Real-Port: 8000".
> 
> I've tried both the $proxy_port and the $server_port
> variables, but they're both 80.

I've found out that if, in 0.6.32, you do:

     proxy_pass        http://localhost:8000;
     proxy_set_header  X-Proxy-Port $proxy_port;

You get 8000 in the HTTP_X_PROXY_PORT header.

However if you do:

     upstream p {
       server localhost:8000
     }

     proxy_pass        http://p;
     proxy_set_header  X-Proxy-Port $proxy_port;

You get 80 in the HTTP_X_PROXY_PORT header.

Is this expected, or does it require a fix?
If so, is it an easy fix for the main devs,
or do you want me to work up a patch?

Thanks.





More information about the nginx mailing list