在NGINX的配置中有时我们需要限制某一用户或者某个网段等访问指定内容,因此需要配置NGINX配置文件,设置方法如下:

网站:www.a.com  a网站我们设置限制192.168.26.70此IP访问:

网站: www.b.com 

编辑配置文件:vim /etc/nginx/nginx.conf

nginx.conf:

  server {

        listen 80;

        server_name www.a.com;

          root /data/www/a.com;

          index index.html index.htm;

       deny 192.168.26.70;     #限制IP或IP段访问此网站

}

  server {

        listen 80;

        server_name www.b.com;

         root /data/www/b.com;

         index index.html index.htm;

      }

}

访问控制access模块:

        allow

        deny

        自上而下依次认证,默认为通过

分别在两台客户机上访问www.a.com,www.b.com观察结果。


wKioL1hrQxDCfkBNAAE-zP7gDS4009.png-wh_50