Environment variables not accessible by mod_rewrite
dms173 opened this issue · 15 comments
It seems like in Apache 2.4, the environment variable being set by MaxMindDBEnv is not accessible by mod_rewrite. Any ideas on how to access it? I've tried the following with no luck:
/etc/apache2//mods-enabled/maxminddb.conf:
MaxMindDBEnable On
MaxMindDBFile COUNTRY_DB /etc/apache2/geoip/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE US VISITOR_COUNTRY=US
/etc/apache2/sites-enabled/000-default.conf:
RewriteEngine On
RewriteCond %{ENV:MM_COUNTRY_CODE} US [OR]
RewriteCond %{ENV:VISITOR_COUNTRY} US
RewriteRule ^(.*)$ http://www.example.com/us/$1 [L]
Both ENV:MM_COUNTRY_CODE and ENV:VISITOR_COUNTRY are empty. Any ideas?
Nevermind that code actually works. Just need to take care that the check is done within the right subrequest within mod_rewrite.
Good to hear! We should provide an example and test case with mod_rewrite though as it is a very common use case.
I have similar problem inside a RewirteMap/RewriteRule:
RewriteRule ^\/((index|home)(\.php|\.jsp))?$ /${locale-to-pub:%{ENV:GEOIP_COUNTRY_CODE}|en}/home.jsp [R=301,NC,L,E=nocache:1]
If I force GEOIP_COUNTRY_CODE with SetEnvIf, it works. It is because SetEnvIf sets the value of env variable at the begining of de request, before mod_rewrite takes acction, But seems like mod_maxmainddb acts after mod rewrite, so mod_rewrite don't have the value seted yet.
Trace error from rewrite mod:
cache lookup FAILED, forcing new map lookup
map lookup FAILED: map=locale-to-pub[txt] key=
A workaround o solution is wellcome, please.
This module's hooks should run before mod_rewrite's hooks. We have a specific test for this.
I encounter the same problem, ENV variables set by mod_maxminddb are not visible by mod_rewrite, but visible by CGI scripts.
mod_maxminddb-1.0.1
libmaxminddb-1.0.4
httpd-2.4.12 (tried 2.4.10, tried static modules and/or loaded)
Compiled apache:
./configure --enable-rewrite
--enable-setenvif --enable-so --enable-ssl --with-mpm=worker
--enable-proxy --enable-proxy-connect --enable-proxy_wstunnel --enable-status
--enable-proxy-ftp --enable-proxy-http
--with-ssl --enable-static-support --enable-headers
--enable-static-htdigest --enable-static-htpasswd
--enable-static-logresolve --enable-static-rotatelogs
--enable-deflate --enable-proxy-http --enable-slotmem_shm
--enable-proxy-balancer --enable-proxy --enable-proxy-connect
--with-included-apr --enable-access_compat --enable-socache_shmcb --enable-remoteip.
____________ httpd.conf
LoadModule rewrite_module /software/apache/modules/mod_rewrite.so
LoadModule maxminddb_module /software/apache/modules/mod_maxminddb.so
LoadModule remoteip_module /software/apache/modules/mod_remoteip.so
RemoteIPHeader IPTEST
MaxMindDBEnable On
MaxMindDBFile CITY_DB /bigdisk0/geoip/share/GeoIP/GeoIP2-City.mmdb
MaxMindDBEnv GEOIP_REGION_CODE CITY_DB/subdivisions/0/iso_code
MaxMindDBEnv MM_COUNTRY_CODE CITY_DB/country/iso_code
MaxMindDBEnv MM_COUNTRY_NAME CITY_DB/country/names/en
MaxMindDBEnv MM_CITY_NAME CITY_DB/city/names/en
-VirtualHost *:80-
SetEnvIf MM_COUNTRY_CODE DE VISITOR_COUNTRY=DE
RewriteCond %{ENV:MM_COUNTRY_CODE} DE [OR]
RewriteCond %{ENV:VISITOR_COUNTRY} DE
RewriteRule . http://www.someplace.com/de/ww?ff=%{ENV:VISITOR_COUNTRY} [L,R=301]
/VirtualHost
RewriteRule did not activated, there is a environment printing script instead.
wget.exe --header "IPTEST: 77.6.124.167" -O - http://10.30.11.171/bin/env.cgi
--2015-06-23 14:41:15-- http://10.30.11.171/bin/env.cgi
Connecting to 10.30.11.171:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: 'STDOUT'
[<=> ] 0 --.-K/s
GEOIP_REGION_CODE="SH"
HTTP_HOST="10.30.11.171"
MMDB_ADDR="77.6.124.167"
MMDB_INFO="result found"
MM_CITY_NAME="Kiel"
MM_COUNTRY_CODE="DE"
MM_COUNTRY_NAME="Germany"
REMOTE_ADDR="77.6.124.167"
[ <=> ] 1,083 --.-K/s in 0s
2015-06-23 14:41:15 (11.0 MB/s) - written to stdout [1083]
We do have a test for this and we have customers using the two together successfully. I see you are using GeoIP2 City; have you contacted support@maxmind.com about this?
Thanks for help, this test was not included in release, I took it and implemented into separate host. It works. I was able to pinpoint issue. I think it is a bug or undocumented feature. ENV variables set by mod_maxminddb are not visible within VirtualHost, but visible inside Directory or Location block!
____ httpd.conf
--VirtualHost
RewriteCond %{ENV:GEOIP_REGION_CODE} SH
RewriteRule . http://www.some1.com/de/ww?ff=%{ENV:GEOIP_REGION_CODE} [L,R=301]
-Location />
RewriteCond %{ENV:GEOIP_REGION_CODE} SH
RewriteRule . http://www.some2.com/de/ww?ff=%{ENV:GEOIP_REGION_CODE} [L,R=301]
-/Location>
wget.exe --header "IPTEST: 77.6.124.167" -O - http://10.30.11.171/bin/env.cgi
--2015-06-23 15:29:03-- http://10.30.11.171/bin/env.cgi
Connecting to 10.30.11.171:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.some2.com/de/ww?ff=SH [following]
--2015-06-23 15:29:03-- http://www.some2.com/de/ww?ff=SH
Interesting. Thanks for point that out. Would you open a specific issue for that? This one is a bit muddled.
Thanks!
Hello Gregory,
"ENV variables set by mod_maxminddb are not visible within VirtualHost, but visible inside Directory or Location block #30"
I see my item was closed. Was it fixed or closed as invalid/cannot reproduce?
Thanks.
Thanks!
—
Reply to this email directly or view it on GitHub.
Best regards,
Yaroslav mailto:yaric@elcosystems.com
That issue was not closed; see the "open" at the top. Rather, it references this issue which was closed by the original reporter.
I have the same issue - maxmind mmdb variables are unavailable to rewrite rules within vhost configuration. If rewrite rules are put into .htaccess or cgi script - everything works like a charm.
Rtoribio@gmail.com
El 21/5/2015 16:06, "Gregory Oschwald" notifications@github.com escribió:
This module's hooks should run before mod_rewrite's hooks
https://github.com/maxmind/mod_maxminddb/blob/master/src/mod_maxminddb.c#L116.
We have a specific test for this
https://github.com/maxmind/mod_maxminddb/blob/greg/mod-rewrite-tests/t/conf/extra.conf.in#L190
.—
Reply to this email directly or view it on GitHub
#27 (comment)
.
rtoribio@riu.com
El 21/5/2015 16:06, "Gregory Oschwald" notifications@github.com escribió:
This module's hooks should run before mod_rewrite's hooks
https://github.com/maxmind/mod_maxminddb/blob/master/src/mod_maxminddb.c#L116.
We have a specific test for this
https://github.com/maxmind/mod_maxminddb/blob/greg/mod-rewrite-tests/t/conf/extra.conf.in#L190
.—
Reply to this email directly or view it on GitHub
#27 (comment)
.