Nginx Proxy + Apache and php5 as apache module SERVER_ADDR problem (HELP!)

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:

 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:


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

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:

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:
Nginx Proxy + Apache and php5 as apache module SERVER_ADDR problem (HELP!)

Do you have mod_rpaf installed in your Apache?

http://stderr.net/apache/rpaf/


Jim O.

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

Posted at Nginx Forum:

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

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

Posted at Nginx Forum:
Re: Nginx Proxy + Apache and php5 as apache module SERVER_ADDR problem (HELP!)

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.

BTW, the apache error:

/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:

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


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:

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.
http://sysoev.ru/en/

Hi Igor,

Any clue on how to solve this?

Thanks!

Posted at Nginx Forum:

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.
http://sysoev.ru/en/

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 but, when configuring
the upstream with EXTERNAL_IP_3, www.websiteA.com displays the info (the
bugged info) of 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) … but eitherway, we still have
the “bugged content” stuff there.

I KNOW! it’s difficult to explain.

Posted at Nginx Forum:

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

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


Igor S.
http://sysoev.ru/en/

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

EXTERNAL_IP_1 is associated with www.websiteA.com but, when configuring
the upstream with EXTERNAL_IP_3, www.websiteA.com displays the info (the
bugged info) of 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) … 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.
http://sysoev.ru/en/

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:

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.
http://sysoev.ru/en/

That worked!

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

Igor, thank you so much for your help!

Posted at Nginx Forum:

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

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:

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:

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: