基于主机(IP)
module ngx_http_access_module
directiver allow #允许 deny #拒接
syntax #allow address |CIDR |UNIX: |ALL;
Context: http,server,location,limit_except
案例:
server {
allow 192.168.8.1;
allow 192.168.7.*;
deny all;
}
基于用户 auth:认证 basic:基本
module ngx_http_auth_basic_module
syntax: auth_basic_user_file file;
Context: http,server,location,limit_excep
#案列
htpasswd -cm /etc/nginx/conf.d/passwd user10
-c 创造
-m 加密
/etc/nginx/conf.d/passwd 创建到那个文件,如果有这个文件就可以不加 - c
用那个网站就在那个网站创建
#案例
vim /etc/nginx/conf.d/default.conf
server {
auth_basic "欢迎来到身份验证页面:p"; #提示信息
auth_basic_user_file /etc/nginx/conf.d/passwd ; #存密码
}