首页 > 其他 > 详细

nginx 禁止某些客户端ip访问

时间:2019-05-17 22:31:52      阅读:257      评论:0      收藏:0      [点我收藏+]

 

1. 在   /etc/nginx/nginx.conf  配置文件的server模块里添加匹配  ( 和location同一级 )

       if ($remote_addr !~ ^(192.168.0.*|127.0.0.1)) {
         rewrite ^.*$ /errorPage/upgrade.html last;
        }

用这种方法, 除去上面包含的ip外的所有客户端的请求都不可以. 包括 POST请求.

技术分享图片

 

2. 在   /etc/nginx/nginx.conf  配置文件的server里location里做限制

    server {
       listen 80;
       server_name tty.bszhihui.com;
       location / {
                allow 111.198.29.223;
                deny all;
            root   /data/wu/web/;
            index  default.php  index.php index.html;
                }

        error_page  404 403     /error.html;

        location = /error.html {
        }
        }

用这种方法, 除了允许的ip可以,拒绝的ip不可以, 规则是从上往下. 但是禁止的 GET请求, POST 不限制. 

技术分享图片

 

nginx 禁止某些客户端ip访问

原文:https://www.cnblogs.com/mingetty/p/10883888.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!