2017-03-03 38 views
0

我想知道是否可以根據ISP阻止請求?如果是的話,那我該怎麼做到呢?我知道如果知道ISP分配的IP地址範圍,我可以阻止這些請求。有什麼方法可以知道這些IP地址嗎?根據它的ISP阻止請求?

回答

0

您可以使用內置的geoip模塊實現該功能。

nginx -V 

查找--with-http_geoip_module

然後你會得到一個數據庫,並將其解壓到/etc/nginx

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz 
gunzip GeoIP.dat.gz 

現在,添加以下到您nginx.conf

geoip_country /etc/nginx/GeoIP.dat; 
map $geoip_country_code $allowed_country { 
default yes; 
CN no; 
} 

這個例子將允許任何人,但不是中國。現在激活它在適當的位置:

if ($allowed_country = no) { 
    return 443; 
} 

現在適用於ISP也一樣,你只需要獲得相應的數據庫。