基于ngx_http_auth_basic_module模块,默认可用
语法:
auth_basic “提示信息”;
auth_basic_user_file /etc/nginx/htpasswd;
配置实现:
①创建用户名和密码存储文件
shell > yum -y install httpd-tools
shell > cd /usr/local/nginx/conf
#生成用户名称和密码(这两个参数自定义)
shell > htpasswd -c ./password.db snljh
#输入密码并再次确认密码
#查看password.db文件是否创建成功
shell > ls
②在配置文件中进行配置
shell > vim /usr/local/nginx/conf/nginx.conf
配置文件内容
#根据业务需求,配置到server段里
#登录框显示的标题提示
auth_basic "test login";
#加载用户名称和密码校验文件
auth_basic_user_file /usr/local/nginx/conf/password.db;
③测试查看