# Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)

**URL:** <https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635>\
**Category:** NGINX\
**Created:** [October 17, 2010, 10:12pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635 "2010-10-17T22:12:54Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 17, 2010, 10:12pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/1 "2010-10-17T22:12:54Z")

</div>

Hi,

First of all, my setup:  
Debian 5  
Apache 2,  
Nginx 0.6.32 as Proxy  
PHP 5 as Apache module  
All installed via apt  
And, (important data), the server handles 5 different ips wich are  
distributed among several websites, so both apache and nginx are  
listening to several ips at the same time.

My problem is that php info is reporting SERVER\_ADDR as 127.0.0.1, and  
Im trying to install an app wich needs to report the server’s ip back to  
a central (external) server. Since it;s reporting 127.0.0.1, I cant make  
it work.

I’ve tryed different aproaches to solve the problem but with no luck so  
far.

I apreciate some help to solve this.

Some of my config files:

nginx.conf (relevant info)

[code]  
http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;  
server\_names\_hash\_bucket\_size 64;  
log\_format main '$remote\_addr - $remote\_user [$time\_local]  
$request ’  
'“$status” $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
#access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
gzip_types text/plain text/css text/javascript text/html

```

application/x-javascript;  
upstream apache {  
server 127.0.0.1:8888;  
}

```
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*;
include /etc/nginx/sites-enabled/*;

#
# The default server
#

```

}[/code]

virtualhost:

```auto
 server {

    server_tokens off;
    listen EXTERNAL_IP_3:80;

   server_name example.com www.example.com;

   location ~ \.(flv|css|js|ico|jpg|png|gif|swf|torrent)$ {
     root /home/example/public_html/;
     break;
   }

    location / {
      default_type text/html;

      proxy_pass http://apache;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
            client_max_body_size 10m;
            client_body_buffer_size 128k;
            proxy_connect_timeout 120;
            proxy_send_timeout 120;
            proxy_read_timeout 120;
            proxy_buffer_size 4k;
            proxy_buffers 4 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;

    }
  }
```

apache virtual host:

```auto

DocumentRoot /home/example/public_html
DirectoryIndex index.php index.htm index.html
ServerName example.com
ServerAlias www.example.com
CustomLog /var/log/apache2/access_example.log combined
ErrorLog /var/log/apache2/apacheerror_example.log

Options +FollowSymLinks
AllowOverride All
Order deny,allow
allow from all
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

```

phpinfo() (relevant info):

```auto
SERVER_SOFTWARE Apache
SERVER_NAME www.example.com
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR 192.168.0.2 (Client IP)
```

Thank you guys!

Posted at Nginx Forum:

> **[Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141655#msg-141655)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 17, 2010, 10:55pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/2 "2010-10-17T22:55:38Z")

</div>

On 10/17/10 4:12 PM, DarkPepe wrote:

> listening to several ips at the same time.
> 
> ```
> '"$status" $body_bytes_sent "$http_referer" '
> gzip_types text/plain text/css text/javascript text/html
> # The default server
> 
> proxy_pass http://apache;
> proxy_buffers 4 32k;
> 
> ```
> 
> [code]  
> Order deny,allow
> 
> [code]  
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,141655,141655#msg-141655](http://forum.nginx.org/read.php?2,141655,141655#msg-141655)

Do you have mod\_rpaf installed in your Apache?

[http://stderr.net/apache/rpaf/](http://stderr.net/apache/rpaf/)

–  
Jim O.

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 17, 2010, 11:00pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/3 "2010-10-17T23:00:03Z")

</div>

yes … it’s installed, but that doesnt fiix the server address ☹

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141665#msg-141665)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 12:10am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/4 "2010-10-18T00:10:23Z")

</div>

On 10/17/10 4:59 PM, DarkPepe wrote:

> yes … it’s installed, but that doesnt fiix the server address ☹
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,141655,141665#msg-141665](http://forum.nginx.org/read.php?2,141655,141665#msg-141665)

It’s possibly how mod\_rpaf is configured in your apache.conf file.

Make certain that mod\_rpaf is loaded and use something like this (mostly  
from page previously linked):

LoadModule rpaf\_module /path/to/modules/mod\_rpaf-2.0.so

RPAFenable On  
RPAFsethostname On  
RPAFproxy\_ips 127.0.0.1  
RPAFheader X-Forwarded-For

–  
Jim O.

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 6:31am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/5 "2010-10-18T06:31:01Z")

</div>

BTW, the apache error:

```auto
/etc/init.d# /etc/init.d/apache2 restart
Restarting web server: apache2We failed to correctly shutdown apache,
so we're now killing all running apache processes. This is almost
certainly suboptimal, so please make sure your system is working as
you'd expect now! (warning).
... waiting Syntax error on line 5 of
/etc/apache2/mods-enabled/rpaf.conf:
Invalid command 'RPAFheader', perhaps misspelled or defined by a
module not included in the server configuration
failed!
```

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141762#msg-141762)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 6:30am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/6 "2010-10-18T06:30:23Z")

</div>

Yes, it’s installed, but the configuration for the debian package is  
different (apt):

```auto

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1

```

If I add RPAFheader X-Forwarded-For apache doesnt start.  
Thanks

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141761#msg-141761)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 8:20am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/7 "2010-10-18T08:20:10Z")

</div>

On Sun, Oct 17, 2010 at 06:09:07PM -0400, Jim O. wrote:

> RPAFenable On  
> RPAFsethostname On  
> RPAFproxy\_ips 127.0.0.1  
> RPAFheader X-Forwarded-For

I’m not sure that RPAFsethostname can set SERVER\_ADDRESS.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 9:16am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/8 "2010-10-18T09:16:38Z")

</div>

Hi Igor,

Any clue on how to solve this?

Thanks!

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141787#msg-141787)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 9:21am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/9 "2010-10-18T09:21:03Z")

</div>

On Mon, Oct 18, 2010 at 03:16:00AM -0400, DarkPepe wrote:

> Hi Igor,
> 
> Any clue on how to solve this?

You may try this:

```
 upstream apache {
        server EXTERNAL_IP:8888;
 }

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 9:33am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/10 "2010-10-18T09:33:36Z")

</div>

Yes, I tryed that, but when using the external IP a weird error ocurrs.

It’s kind of difficult to explain, but the website shows some random  
content from any of the scripts hosted in that particular virtualhost  
instead of showing the appropiate info.

Also other websites using different ips get mixed up with the website  
associated to that ip (EXTERNAL\_IP\_3)…

For example:

EXTERNAL\_IP\_1 is associated with [www.websiteA.com](http://www.websiteA.com) but, when configuring  
the upstream with EXTERNAL\_IP\_3, [www.websiteA.com](http://www.websiteA.com) displays the info (the  
bugged info) of [www.example.com](http://www.example.com) (wich is associated to EXTERNAL\_IP\_3).

Probably that can be solved by using the correct IP for each virtualhost  
in proxy\_pass (instead of [http://apache](http://apache)) … but eitherway, we still have  
the “bugged content” stuff there.

I KNOW! it’s difficult to explain.

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141792#msg-141792)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 9:19am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/11 "2010-10-18T09:19:47Z")

</div>

On Sun, Oct 17, 2010 at 04:12:06PM -0400, DarkPepe wrote:

> }  
> BTE, this “break” is just waste of CPU cycles.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 11:44am UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/12 "2010-10-18T11:44:03Z")

</div>

On Mon, Oct 18, 2010 at 03:32:14AM -0400, DarkPepe wrote:

> EXTERNAL\_IP\_1 is associated with [www.websiteA.com](http://www.websiteA.com) but, when configuring  
> the upstream with EXTERNAL\_IP\_3, [www.websiteA.com](http://www.websiteA.com) displays the info (the  
> bugged info) of [www.example.com](http://www.example.com) (wich is associated to EXTERNAL\_IP\_3).
> 
> Probably that can be solved by using the correct IP for each virtualhost  
> in proxy\_pass (instead of [http://apache](http://apache)) .. but eitherway, we still have  
> the “bugged content” stuff there.

nginx can pass its address in HTTP header, you may try to use it on PHP  
side:

```
  proxy_set_header X-Server-Address $server_address;

```

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 6:10pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/13 "2010-10-18T18:10:14Z")

</div>

On Mon, Oct 18, 2010 at 12:04:57PM -0400, DarkPepe wrote:

> Ok, I added that to the vhost config but it gives me an error:
> 
> ```auto
> nginx -t
> 2010/10/18 13:03:08 [emerg] 10500#0: unknown "server_address" variable
> 2010/10/18 13:03:08 [emerg] 10500#0: the configuration file
> /etc/nginx/nginx.conf test failed
> ```

Sorry, $server\_addr.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 6:26pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/14 "2010-10-18T18:26:43Z")

</div>

That worked!

Now phpinfo() is reporting the correct server address!.

Igor, thank you so much for your help!

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141949#msg-141949)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [October 18, 2010, 6:05pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/15 "2010-10-18T18:05:49Z")

</div>

Ok, I added that to the vhost config but it gives me an error:

```auto
nginx -t
2010/10/18 13:03:08 [emerg] 10500#0: unknown "server_address" variable
2010/10/18 13:03:08 [emerg] 10500#0: the configuration file
/etc/nginx/nginx.conf test failed
```

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,141935#msg-141935)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [April 30, 2011, 12:02pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/16 "2011-04-30T12:02:35Z")

</div>

Hey,  
I have the same issue, and tried adding:  
proxy\_set\_header X-Server-Address $server\_addr;

but I still have:  
SERVER\_ADDR = 127.0.0.1

but I do have:  
HTTP\_X\_SERVER\_ADDRESS = [THE\_REAL\_SERVER\_IP]

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,194638#msg-194638)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx

---

<div class="post-metadata">

**Author:** ![DarkPepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DarkPepe](https://www.ruby-forum.com/u/DarkPepe)\
**Post date:** [April 30, 2011, 12:14pm UTC](https://www.ruby-forum.com/t/nginx-proxy-apache-and-php5-as-apache-module-server-addr-problem-help/197635/17 "2011-04-30T12:14:18Z")

</div>

OK, maybe it’ll be a good idea to clarify me real problem.  
when I access a site hosted on my server with HTTP, I get SERVER\_ADDR =  
127.0.0.1  
when I access the same site with HTTPS, I get SERVER\_ADDR =  
[THE\_REAL\_SERVER\_IP]

Posted at Nginx Forum:

> **[Re: Nginx Proxy + Apache and php5 as apache module SERVER\_ADDR problem (HELP!)](https://forum.nginx.org/read.php?2,141655,194639#msg-194639)**
>
> Hi, First of all, my setup: Debian 5 Apache 2, Nginx 0.6.32 as Proxy PHP 5 as Apache module All installed via apt And, (important data), the server handles 5 different ips wich are distributed among several websites, so both apache and nginx
