欢迎光临
我们一直在努力

nginx限制IP访问

1、服务器全局限制

vi /etc/nginx/nginx.conf
              user    nginx
              allow  192.168.10.10;            #允许IP为192.168.10.10的用户访问
              allow   192.168.200.0/24;        #允许IP为192.168.200.0/24段的用户访问
              deny     all; 

#除以上两条允许的外,其他全部禁止访问

2、站点限制

location / {
               allow   192.168.10.10;          #允许IP为192.168.10.10的用户访问
               allow   192.168.200.0/24;       #允许IP为192.168.200.0/24段的用户访问
               deny     all;                   #除以上两条允许的外,其他全部禁止访问
           }

3、目录限制

location /test {
                allow   192.168.10.10;          #允许IP为192.168.10.10的用户访问
                allow   192.168.200.0/24;       #允许IP为192.168.200.0/24段的用户访问
                deny     all;                   #除以上两条允许的外,其他全部禁止访问
               }

规则越靠前优先级越高,优先匹配,匹配之后不再匹配其后的策略。

未经允许不得转载:SRE空间 » nginx限制IP访问

分享到:更多 ()

oracle