15. Nginx Geo
GeoLite2 City
과 GeoLite2 Country
하면 됩 니 다 source
옵션 은 $remote_addr
사용자 IP 를 분석 하고 다른 변수 http {
...
geoip2 /etc/nginx/vendor/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code default=US source=$remote_addr country iso_code;
$geoip2_data_country_name country names en;
}
geoip2 /etc/nginx/vendor/GeoLite2-City.mmdb {
$geoip2_data_city_name default=London city names en;
}
fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param CITY_NAME $geoip2_data_city_name;
....
server {
listen 8081;
server_name www.siguoya.name;
location / {
if ($geoip2_data_country_code != 'CN'){
return 403;
}
default_type text/plain;
return 200 "$remote_addr $geoip2_data_country_code $geoip2_data_country_name $geoip2_data_city_name";
}
}
}
방문:
http://www.siguoya.name:8081/
113.111.3.206 CN China Guangzhou
낡은 방법
maxmind 에서 dat 형식의 데이터 다운로드 및 유 지 를 제공 하지 않 기 때문에 다음 방법 은 폐기 되 었 습 니 다.
IP 데이터베이스 다운로드 주소: 국가 데이터베이스: http://geolite.maxmind.com/do... 도시 데이터베이스: http://geolite.maxmind.com/do...
http {
geoip_country /path/to/GeoIP.dat;
geoip_city /path/to/GeoLiteCity.dat;
server{
listen 3592;
location / {
default_type text/plain;
if ($geoip_country_code != 'CN'){
return 403;
}
return 200 "$remote_addr $geoip_city_country_name $geoip_country_code $geoip_city";
}
}
}
방문:
http://www.siguoya.name:3592/
119.32.216.122 China CN Guangzhou
특정한 제목 으로 읽다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.