Welcome! Log In Create A New Profile

Advanced

Как сделать определение географии по ip в параметре урла?

Posted by varan 
допустим, запрос такой: mysite.ru/blabla.php?myip=1.2.3.4
и я хочу прокидывать заголовок с гео-информацией по этому параметру myip

я нашел в документации следующее:

Describes the dependency of values of the specified variable on the client IP address. By default, the address is taken from the $remote_addr variable, but it can also be taken from another variable (0.7.27), for example:

geo $arg_remote_addr $geo {
...;
}

но как мне присвоить переменной $arg_remote_addr значение из параметра myip я не нашел.
И еще вопрос, есть ли подводные камни в таком определении гео.
Привет.
Нужно использовать моудль:
http://nginx.org/en/docs/http/ngx_http_geo_module.html

В http секции конфига прописываеш:

geo $arg_myip $country {
default XX;
include /usr/local/etc/nginx/geo.conf;
}

формат файла geo.conf
....
1.0.0.0/24 AU;
1.0.1.0/24 CN;
1.0.2.0/23 CN;
1.0.4.0/22 AU;
1.0.8.0/21 CN;
1.0.16.0/20 JP;
....

Этот файл делается из MaxMind GeoCountry скриптом http://trac.nginx.org/nginx/browser/nginx/contrib/geo2nginx.pl

Удачи.
Забыл:
в файл fastcgi_params нужно добавить:

fastcgi_param GEOIP_COUNTRY_CODE $country;

тогда можна использовать переменную в своих скриптах.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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