NGINX屏蔽ip,https(443端口)有效,而http(80端口)无效

自己设置的ipblock.conf文件,deny了自己的手机ip
然后include ipblock.conf;到服务器的nginx.conf的http{}下面
效果:

  • 网站1是https协议,ip屏蔽成功
  • 网站2是http协议,ip屏蔽无效

然后将在http网站的conf文件里面添加了include ipblock.conf;依然无效
然后将deny ip;直接写到http协议网站的conf文件里面,还是无法屏蔽

请教各位上仙,这个怎么解决

相关配置:
文件夹/conf/下面
文件:ipblock.conf

deny ip;
…………

文件:nginx.conf

http
    {

        include       mime.types;
        default_type  application/octet-stream;
        include ipblock.conf;
        …………

文件夹/conf/vhost下面
网站1(https协议).conf

server
    {
        listen 80;
        #listen [::]:80;
        server_name www.name1.com name1.com *.name1.com;
        return 301 https://www.nam1e.com$request_uri;
    }

server
    {
        listen 443 ssl http2;
        #listen [::]:443 ssl http2;
        server_name www.name1.com name1.com *.name1.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.name1.com;
        ssl on;
        …………

网站2(http协议).conf

server
    {
        listen 80;
        #listen [::]:80;
        server_name www.name2.com name2.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.name2.com;
        
        //这儿添加的include ipblock.conf;
        //或者直接写的deny ip;


阅读 4.9k
2 个回答

可能的原因:

  1. 你的手机流量被运营商做了缓存
  2. 你的手机的浏览器开启了类似的“省流量”的功能,比如Chrome和UC都有这种功能
  3. 运营商对于不同协议,走的出口不一样

简而言之,尽量不要用手机来做这种涉及到IP的测试,除非你确定中间经过什么


可以增加两项配置来做测试:

location = /ip {
    default_type text/plain;
    allow all;
    return 200 "$remote_addr, $realip_remote_addr, $http_x_real_ip";
}
location = /deny {
    deny all;
}
  1. 然后用手机访问 /ip,看下你服务器获取到的IP是多少;
  2. 用手机访问 /deny,看屏蔽是否有效。

看起来配置没有问题。

若是在 ipblock.conf 文件中使用了静态 IP,例如

deny 1.2.3.4;
allow all;

那很可能是你的手机浏览器访问 http 时使用了某些加速服务,它透过第三方服务 IP 去访问你的网站。
但由于 https 是加密连接,无法加速,因此使用的是你的手机 IP。

你可以通过查询 nginx 访问日志,或在服务器抓包来确认。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题