# IP address of fastcgi server?

**URL:** <https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344>\
**Category:** NGINX\
**Created:** [October 12, 2010, 3:43am UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344 "2010-10-12T03:43:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [October 12, 2010, 3:43am UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344/1 "2010-10-12T03:43:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [October 12, 2010, 8:28am UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344/2 "2010-10-12T08:28:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [October 12, 2010, 1:05pm UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344/3 "2010-10-12T13:05:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [October 12, 2010, 12:55pm UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344/4 "2010-10-12T12:55:15Z")

</div>

Someone else suggested:

fastcgi\_param UPS\_SERVER\_ADDR $upstream\_addr;

and get $\_SERVER[“UPS\_SERVER\_ADDR”].

?

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [October 12, 2010, 9:01pm UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344/5 "2010-10-12T21:01:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [October 12, 2010, 9:25pm UTC](https://www.ruby-forum.com/t/ip-address-of-fastcgi-server/196344/6 "2010-10-12T21:25:38Z")

</div>

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.
