好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

nginx访问限制

nginx中通过 访问 控制来允许或拒绝某些IP或用户 访问 。常用的方法如下: 一:通过ngx_http_access_module模块来允许某些IP的客户端 访问 ,通过关键字allow和deny来实现 allow :允许指定的网络地址 访问 。 deny :拒绝指定的网络地址 访问 。 location /

nginx中通过 访问 控制来允许或拒绝某些IP或用户 访问 。常用的方法如下:


一:通过ngx_http_access_module模块来允许某些IP的客户端 访问 ,通过关键字allow和deny来实现

allow :允许指定的网络地址 访问 。

deny :拒绝指定的网络地址 访问 。

location / {
    deny    192.168.2.6;
    allow   192.168.2.0/24;
    deny    all;
} 

上面的例子中,规则从上到下依次检测,允许192.168.2.0/24网络 访问 ,但192.168.2.6除外,其余的都拒绝。

二:基于ngx_http_auth_basic_module模块允许使用“HTTP基本认证”协议验证用户名和密码来 限制 对资源的 访问 。

auth_basic STRING|off; //默认为off

auth_basic_user_file FIEL; 指定保存用户名和密码的文件。

location / {
    auth_basic "private";
    auth_basic_user_file /usr/nginx/.htpasswd;
} 
location / {
    satisfy any;
    allow 192.168.2.0/24;
    deny all;
    auth_basic "private";
    auth_basic_user_file /usr/nginx/.htpasswd;
} 

上面例子表示只要满足一组 限制 ,即可 访问 。


阿三哥

查看更多关于nginx访问限制的详细内容...

  阅读:67次