Apache mod_proxy

Hello everyone,

I have a small problem.

I have two servers behind my router, both are web servers with opensuse on it. Router redirects traffic on 80 to first server.

But because first one is not so powerful I moved one of the web sites to the second one. I used mod_proxy to redirect domain to second server. I also added DNS record that resolve that domain to second server.

Now, everything is working… except I can’t see client source IP’s in log file of second server instead of that is see IP of my proxy server :frowning:

What can I do to resolve this problem?

Thanks for your help.

Here is my vhost config for the domain

<VirtualHost 192.168.0.4>
    ServerName www.domain.com
    ServerAlias www.domain.com

    ProxyRequests Off

    CustomLog       /var/log/apache2/domain.com-access.log     combined
    ErrorLog        /var/log/apache2/domain.com-error.log
    LogLevel        warn

    # don't loose time with IP address lookups
    HostnameLookups Off

    # needed for named virtual hosts
    UseCanonicalName Off

    # configures the footer on server-generated documents
    ServerSignature On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://www.domain.com/
    ProxyPassReverse / http://www.domain.com/

    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

You need the ProxyPreserveHost directive.

Thanks for quick reply ken_yap. I already tried this before but wit no success… anyway I added this directive again.

This is what I get on second server when I access site with my mobile phone.

192.168.0.4 - - [07/Mar/2009:13:11:14 +0100] "GET /skin/frontend/default/modern/images/logo.png HTTP/1.1" 200 5439 "http://www.domain.com/" "SonyEricssonK610i/R1JG Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"

Server 2 vhost file

<VirtualHost 192.168.0.5>

DocumentRoot /srv/www/htdocs/www.domain.com

ServerName www.domain.com
ServerAlias www.domain.com

CustomLog       /var/log/apache2/domain.com-access.log     combined
ErrorLog        /var/log/apache2/domain.com-error.log
LogLevel        warn

<Directory "/srv/www/htdocs/www.domain.com">
allow from all
Options -Indexes
AllowOverride All
</Directory>

</VirtualHost>

Server1: With preserve host directive.

<VirtualHost 192.168.0.4>
    ServerName www.domain.com
    ServerAlias www.domain.com

    ProxyRequests Off

    CustomLog       /var/log/apache2/domain.com-access.log     combined
    ErrorLog        /var/log/apache2/domain.com-error.log
    LogLevel        warn

    # don't loose time with IP address lookups
    HostnameLookups Off

    # needed for named virtual hosts
    UseCanonicalName Off

    # configures the footer on server-generated documents
    ServerSignature On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPreserveHost On
    ProxyPass / http://www.domain.com/
    ProxyPassReverse / http://www.domain.com/

    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

The real client address is found in the X-Forwarded-For header. You need to adjust your custom log format to capture this.