Welcome! Log In Create A New Profile

Advanced

help!!! how to use geoip with nginx

Posted by isumido 
help!!! how to use geoip with nginx
January 11, 2010 02:29AM
hello...

im rookie...
i wannt use geoip with nginx.
and.... use environment variable GeoIP database.

use nginx 0.8.31 and.. ./configure ~~~~ --with-geoip_module

i set to nginx.conf
-----------------------------
geoip_country /usr/local/share/GeoIP.dat

and...wannt use it

ip.php
<?
print $_SERVER[COUNTRY];
print $geoip_country_by_name('10.10.10.10');
?>

but...no ans...

how can i use geoip with nginx for PHP?

help me.!!!



Edited 1 time(s). Last edit at 01/11/2010 02:29AM by isumido.
Re: help!!! how to use geoip with nginx
January 12, 2010 11:29PM
I don't think "$geoip_country_by_name" takes an argument like that, but rather returns data based on the client's IP. At least it's not in the Wiki. See http://wiki.nginx.org/NginxHttpGeoIPModule. Even if it did it should never find one that since it's an internal IP. Further, you can only use that variable within nginx's configuration files, not within a PHP script.

Something like

[code]
if ($geoip_country_code = XX) {
do something;
}

if ($geoip_country_code = YY) {
do something else;
}
[/code]

It's possible that you can pass $geoip_country_code as a fastcgi_param and then use it within you PHP script(s) as necessary. I haven't tried it so YMMV/

--
Jim Ohlstein
Re: help!!! how to use geoip with nginx
November 15, 2010 04:49PM
Jim Ohlstein Wrote:
-------------------------------------------------------
> I don't think "$geoip_country_by_name" takes an
> argument like that, but rather returns data based
> on the client's IP. At least it's not in the Wiki.
> See http://wiki.nginx.org/NginxHttpGeoIPModule.
> Even if it did it should never find one that since
> it's an internal IP. Further, you can only use
> that variable within nginx's configuration files,
> not within a PHP script.
>
> Something like
>
>
> if ($geoip_country_code = XX) {
> do something;
> }
>
> if ($geoip_country_code = YY) {
> do something else;
> }
>
>
> It's possible that you can pass
> $geoip_country_code as a fastcgi_param and then
> use it within you PHP script(s) as necessary. I
> haven't tried it so YMMV/

FYI, I read this post and this technique works. For future reference for others. Just add to your configuration file:

fastcgi_param COUNTRY $geoip_country_name;
fastcgi_param CITY $geoip_city;
fastcgi_param REGION $geoip_region;

... and the PHP script has access to the GeoIP data. This significantly improved performance on my app versus the default PHP module for geoip.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 150
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