Welcome! Log In Create A New Profile

Advanced

Help needed using GEOIP w/nginx

Posted by bquiat 
Help needed using GEOIP w/nginx
July 20, 2011 02:55PM
Trying to use GEOIP with nginx. nginx is configured --with-http_geoip_module and Maxmind free db is installed. I have tried two approaches, both fail.

Approach 1: In http section add:
geoip_country /root/GEOIP/GeoIP.dat; #path to geo db

Then try to use $geoip_country_code in server section, for example:
rewrite ^/(.*)$ http://$host:81/$1?country=$geoip_country_code permanent;

Result: returns empty geo variables. Appears to be missing some kind of invocation to the geo lookup.

Approach 2:
Based on forum posts for older nginx versions I tried fetching the .CSV version from Maxmind, converting it to nginx-compatible txt with the
contributed perl script, and including it in http section with:
geo $myCountry (
default no;
include /usr/local/nginx/conf/nginxGeo.txt
}

then in server section:
rewrite ^/(.*)$ http://$host:81/$1?country=$myCountry permanent;

Result: Browser page hangs then fails with server not responding. No redirection is supplied to address bar.

Please help, thanks!

Barry Q.
Re: Help needed using GEOIP w/nginx
July 21, 2011 07:26AM
Hi,

Your configuration seems OK, except that I never tried to pass GeoIP variables via GET arguments in the rewrite rule. I set them in the location block:

location ~ ^(?<SCRIPT_FILENAME>.+\.php)(?<PATH_INFO>.*)$ {
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
fastcgi_param GEOIP_CITY_NAME $geoip_city;
...
}

Perhaps, instead of rewrite, you can also create the specific location block, which would pass control to your script, along with $geoip_* vars.

Make sure that GeoIP.dat is actually readable by the user running nginx.
Re: Help needed using GEOIP w/nginx
July 21, 2011 08:04PM
Thanks John. As you suggest, GeoIP variables don't work when passed to rewrite. I exposed mine using proxy_pass_header (instead of fastcgi_param) and it works.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 285
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready