1.基于IP
此指令可以在http、server、location块中配置,由ngx_http_access_module模块支持的。
location {
deny 192.168.1.1; 拒绝此IP访问
allow 192.168.1.0/24;允许该网段访问
deny all;拒绝所有
}
从上到下开始匹配,匹配到了则停止。
2.基于密码
该认证由ngx_http_auth_basic_module模块支持的。默认已安装
该种认证需要用户及密码
auth_pasic string | off; string为开启 off为关闭
auth_pasic_user_file file; 其中file是密码文件的绝对路径
密码文件的明文格式为:
user1:password1
user2:password 2
如果需要对密码加密可使用该命令:
#htpasswd -c -d /usr/local/nginx/conf/pass_file username
运行后输入密码即可。