我有一台nginx服务器,并从CN / JP和某些英国获得了大量垃圾邮件。
我如何阻止访问这些国家? 我已经尝试过GeoIP,但无法正常工作...
文件的一部分:/etc/nginx/nginx.conf
http {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allowed_country {
default yes;
CN no;
JP no;
}
include /etc/nginx/mime.types;
文件的一部分:/etc/nginx/conf.d/default.conf (我的HTTPS部分中的位置块以进行测试)
location /geo {
if ($allowed_country = no) {
return 444;
}
}
nginx -t
重新获得成功
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
/etc/init.d/nginx restart
用[确定]重新干净
Restarting nginx nginx [OK]
我希望CN / JP获得444未发送标头或403被拒绝。这样一来,他们就无法在网站上访问任何内容。但是其他国家可以使用。
从这两个国家/地区访问后,我的日志才完全可用。