Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx-阻止国家访问网站_Nginx_Geoip - Fatal编程技术网

Nginx-阻止国家访问网站

Nginx-阻止国家访问网站,nginx,geoip,Nginx,Geoip,我有一台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_cou

我有一台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部分中用于测试的位置块)

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重新启动
与[确定]完全一致

Restarting nginx nginx          [OK]
我希望CN/JP发送444 no头或403拒绝。他们无法访问网站上的内容。但其他国家也可以进入


从这两个国家访问之后,我的日志就充满了访问权限。

nginx-t恢复正常了吗?因为我很确定你必须引用那些
“yes”
“no”
s.@Sammitch我刚刚试着把yes&no包装在“yes”“no”中。。。同样的结果,不阻塞cCN/JP连接(使用JP中的VPN进行测试)@Twml你能找到解决方案吗?
nginx-t
恢复正常了吗?因为我很确定你必须引用那些
“yes”
“no”
s.@Sammitch我刚刚试着把yes&no包装在“yes”“no”中。。。同样的结果,不阻塞cCN/JP连接(使用JP中的VPN进行测试)也无济于事@Twml您能找到解决方案吗?
Restarting nginx nginx          [OK]