IP address of fastcgi server?

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?

Thanks

Hello!

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

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 D.

Hello!

On Tue, Oct 12, 2010 at 06:53:32AM -0400, Ilan B. wrote:

Someone else suggested:

fastcgi_param UPS_SERVER_ADDR $upstream_addr;

and get $_SERVER[“UPS_SERVER_ADDR”].

?

No, this won’t work due to reasons I already outlined:

[…]

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).

[…]

Variable $upstream_addr will be empty during creation request to
upstream.

And just a side note: variable $upstream_addr contains not a
single address, but a list of upstream addresses tried.

Maxim D.

Someone else suggested:

fastcgi_param UPS_SERVER_ADDR $upstream_addr;

and get $_SERVER[“UPS_SERVER_ADDR”].

?

On 12/10/2010 02:41, Ilan B. wrote:

server processing the php request?

You can obtain the IP address of the machine running the script with

$_server[‘SERVER_ADDR’]

Regards

Ian

Unfortunately, that does not work per previous posts, that only shows
the
front facing web server address…

We have a work around, thanks.

A small configuration file on each server can be read by the php code to
identify which machine it is.