IP address of fastcgi server?

Maxim Dounin mdounin at mdounin.ru
Tue Oct 12 10:26:40 MSD 2010


Hello!

On Mon, Oct 11, 2010 at 09:41:32PM -0400, Ilan Berkner wrote:

> Hi All,
> 
> We're doing some profiling and one of the parameters we'd like to get is the
> IP address of the fastcgi (in this case php-fpm) server that processed the
> request.  PHP $_SERVER['server_addr'] returns the external address of the
> nginx server per our fastcgi configuration:
> 
> fastcgi_param  SERVER_ADDR        $server_addr;
> 
> Is this correct behavior? is there a way to get the local address of the
> server processing the php request?

Yes, SERVER_ADDR is expected to contain http server address, not 
the address of fastcgi application.

Moreever, upstream's address (fastcgi application address in your 
case) isn't available when nginx creates request to upstream (as 
particular upstream server isn't selected yet, and even after 
selection it may change due to proxy_next_upstream). 

You should be able to find out fastcgi application's address in 
fastcgi application itself, it's just a matter of calling 
getpeername() on connection socket.  Not idea how to do it in php 
though.

Maxim Dounin



More information about the nginx mailing list