Apache reverse proxy / mod_rewrite behaviour
Apache reverse proxy / mod_rewrite behaviour
am 29.01.2010 10:49:07 von Raymond Zeilstra
Hello,
I'm trying to redirect visitors from certain countries using GeoIP. I'm
using Apache reverse proxy and pound as loadbalancer:
Ubuntu Server 9.01 64bits
Apache 2.2.11 (mod_proxy, mod_proxy_http, mod_cache, mod_disk_cache,
mod_rewrite, mod_geoip)
The problem I'm encountering is that the first time a request is being
rewritten and redirected, but after a few times it's ignoring the
rewrite rules.
Here's the Apache config:
GeoIPEnable On
GeoIPScanProxyHeaders On
GeoIPDBFile /www/GeoIP.dat
RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(nl|be)$ [NC]
RewriteCond %{HTTP_HOST} !^(nl|be)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L]
LogFormat "%{X-Forwarded-For}i %{Host}i %l %u %t \"%r\" %>s %b
\"%{Referer}i\" \"%{User-Agent}i\" %D"
TransferLog /apache/logs/www.domain.com.access.log
ErrorLog /apache/logs/www.domain.com.error.log
ProxyRequests Off
Order deny,allow
Allow from all
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
ProxyPreserveHost On
CacheRoot /cachedisk
CacheEnable disk /
CacheMaxFileSize 10000000
CacheDirLevels 5
CacheDirLength 1
CacheDisable www.domain.com
Now a wget gives me the following result with an empty disk cache:
# wget http://nl.domain.com/
Resolving nl.domain.com... 1.2.3.4
Connecting to nl.domain.com|1.2.3.4|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.domain.com// [following]
Resolving www.domain.com... 1.2.3.4
....
This is what I want, but after 2 or 3 times and I assume the request is
being cached, then this happens:
# wget http://nl.domain.com/
Resolving nl.domain.com... 1.2.3.4
Connecting to nl.domain.com|1.2.3.4|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 36330 (35K) [text/html]
Saving to: `index.html'
Also in the first case the request is being logged in the Apache access
log, but the second one I can't even find in the access logs.
So my question is why does the rewriting work with a clean cache disk,
but doesn't if (at least I assume) data is returned from the disk cache
and why isn't there a log entry in the access log in the latter case ?
I hope someone has any ideas where I'm going wrong!
Thanks,
Raymond
------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
RE: Apache reverse proxy / mod_rewrite behaviour
am 01.02.2010 10:01:46 von Emmanuel Bailleul
> -----Message d'origine-----
> De=A0: Raymond Zeilstra [mailto:Raymond@wannahaves.nl]
> Envoyé : vendredi 29 janvier 2010 10:49
> À : users@httpd.apache.org
> Objet=A0: [users@httpd] Apache reverse proxy / mod_rewrite behaviour
>=20
>=20
>=20
> Hello,
>=20
> I'm trying to redirect visitors from certain countries using GeoIP. I'm
> using Apache reverse proxy and pound as loadbalancer:
>=20
> Ubuntu Server 9.01 64bits
> Apache 2.2.11 (mod_proxy, mod_proxy_http, mod_cache, mod_disk_cache,
> mod_rewrite, mod_geoip)
>=20
> The problem I'm encountering is that the first time a request is being
> rewritten and redirected, but after a few times it's ignoring the
> rewrite rules.
> Here's the Apache config:
>=20
>
>=20
> GeoIPEnable On
> GeoIPScanProxyHeaders On
> GeoIPDBFile /www/GeoIP.dat
>=20
> RewriteEngine On
>=20
> RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(nl|be)$ [NC]
> RewriteCond %{HTTP_HOST} !^(nl|be)\.domain\.com$ [NC]
> RewriteRule ^(.*)$ http://www.domain.com/$1 [L]
>=20
> LogFormat "%{X-Forwarded-For}i %{Host}i %l %u %t \"%r\" %>s %b
> \"%{Referer}i\" \"%{User-Agent}i\" %D"
> TransferLog /apache/logs/www.domain.com.access.log
> ErrorLog /apache/logs/www.domain.com.error.log
>=20
> ProxyRequests Off
>=20
>
> Order deny,allow
> Allow from all
>
>=20
> ProxyPass / http://127.0.0.1:8080/
> ProxyPassReverse / http://127.0.0.1:8080/
> ProxyPreserveHost On
>=20
> CacheRoot /cachedisk
> CacheEnable disk /
> CacheMaxFileSize 10000000
> CacheDirLevels 5
> CacheDirLength 1
> CacheDisable www.domain.com
>=20
>
>=20
> Now a wget gives me the following result with an empty disk cache:
>=20
> # wget http://nl.domain.com/
> Resolving nl.domain.com... 1.2.3.4
> Connecting to nl.domain.com|1.2.3.4|:80... connected.
> HTTP request sent, awaiting response... 302 Found
> Location: http://www.domain.com// [following]
> Resolving www.domain.com... 1.2.3.4
> ...
>=20
> This is what I want, but after 2 or 3 times and I assume the request is
> being cached, then this happens:
>=20
> # wget http://nl.domain.com/
> Resolving nl.domain.com... 1.2.3.4
> Connecting to nl.domain.com|1.2.3.4|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 36330 (35K) [text/html]
> Saving to: `index.html'
>=20
> Also in the first case the request is being logged in the Apache access
> log, but the second one I can't even find in the access logs.
> So my question is why does the rewriting work with a clean cache disk,
> but doesn't if (at least I assume) data is returned from the disk cache
> and why isn't there a log entry in the access log in the latter case ?
>=20
> I hope someone has any ideas where I'm going wrong!
>=20
> Thanks,
> Raymond
>=20
Maybe : http://httpd.apache.org/docs/2.2/caching.html#overview
(...)
This means that any other stages that might ordinarily happen in the proces=
s of serving a request -- for example being handled by mod_proxy, or mod_re=
write -- won't happen. But then this is the point of caching content in the=
first place.
(...)
Emmanuel
------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
RE: RE: Apache reverse proxy / mod_rewrite behaviour
am 01.02.2010 18:24:03 von Raymond Zeilstra
Hi Emmanuel,
Hmm, must have missed that bit! But thanks, this was indeed the problem!
I've setup another proxy in front with just the rewriting and now it =
works like a charm!
Cheers,
Raymond
-----Original Message-----
From: Emmanuel Bailleul [mailto:Emmanuel.Bailleul@telindus.fr]=20
Sent: maandag 1 februari 2010 10:02
To: users@httpd.apache.org
Subject: [users@httpd] RE: Apache reverse proxy / mod_rewrite behaviour
> -----Message d'origine-----
> De=A0: Raymond Zeilstra [mailto:Raymond@wannahaves.nl] Envoyé : =
vendredi=20
> 29 janvier 2010 10:49 À : users@httpd.apache.org Objet=A0: =
[users@httpd]=20
> Apache reverse proxy / mod_rewrite behaviour
>=20
>=20
>=20
> Hello,
>=20
> I'm trying to redirect visitors from certain countries using GeoIP.=20
> I'm using Apache reverse proxy and pound as loadbalancer:
>=20
> Ubuntu Server 9.01 64bits
> Apache 2.2.11 (mod_proxy, mod_proxy_http, mod_cache, mod_disk_cache,=20
> mod_rewrite, mod_geoip)
>=20
> The problem I'm encountering is that the first time a request is being =
> rewritten and redirected, but after a few times it's ignoring the=20
> rewrite rules.
> Here's the Apache config:
>=20
>
>=20
> GeoIPEnable On
> GeoIPScanProxyHeaders On
> GeoIPDBFile /www/GeoIP.dat
>=20
> RewriteEngine On
>=20
> RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(nl|be)$ [NC] RewriteCond=20
> %{HTTP_HOST} !^(nl|be)\.domain\.com$ [NC] RewriteRule ^(.*)$=20
> http://www.domain.com/$1 [L]
>=20
> LogFormat "%{X-Forwarded-For}i %{Host}i %l %u %t \"%r\" %>s %b=20
> \"%{Referer}i\" \"%{User-Agent}i\" %D"
> TransferLog /apache/logs/www.domain.com.access.log
> ErrorLog /apache/logs/www.domain.com.error.log
>=20
> ProxyRequests Off
>=20
>
> Order deny,allow
> Allow from all
>
>=20
> ProxyPass / http://127.0.0.1:8080/
> ProxyPassReverse / http://127.0.0.1:8080/ ProxyPreserveHost On
>=20
> CacheRoot /cachedisk
> CacheEnable disk /
> CacheMaxFileSize 10000000
> CacheDirLevels 5
> CacheDirLength 1
> CacheDisable www.domain.com
>=20
>
>=20
> Now a wget gives me the following result with an empty disk cache:
>=20
> # wget http://nl.domain.com/
> Resolving nl.domain.com... 1.2.3.4
> Connecting to nl.domain.com|1.2.3.4|:80... connected.
> HTTP request sent, awaiting response... 302 Found
> Location: http://www.domain.com// [following] Resolving=20
> www.domain.com... 1.2.3.4 ...
>=20
> This is what I want, but after 2 or 3 times and I assume the request=20
> is being cached, then this happens:
>=20
> # wget http://nl.domain.com/
> Resolving nl.domain.com... 1.2.3.4
> Connecting to nl.domain.com|1.2.3.4|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 36330 (35K) [text/html]
> Saving to: `index.html'
>=20
> Also in the first case the request is being logged in the Apache=20
> access log, but the second one I can't even find in the access logs.
> So my question is why does the rewriting work with a clean cache disk, =
> but doesn't if (at least I assume) data is returned from the disk=20
> cache and why isn't there a log entry in the access log in the latter =
case ?
>=20
> I hope someone has any ideas where I'm going wrong!
>=20
> Thanks,
> Raymond
>=20
Maybe : http://httpd.apache.org/docs/2.2/caching.html#overview
(...)
This means that any other stages that might ordinarily happen in the =
process of serving a request -- for example being handled by mod_proxy, =
or mod_rewrite -- won't happen. But then this is the point of caching =
content in the first place.
(...)
Emmanuel
------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server =
Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.432 / Virus Database: 271.1.1/2645 - Release Date: 01/31/10 =
19:35:00
------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org