通过Nginx实现web页面的用户认证,用户名为:admin,密码为:654321
1.修改Nginx配置文件
# vim /usr/local/nginx/conf/nginx.conf
......
server {
listen 80;
server_name localhost;
auth_basic "Input Password:"; //添加认证提示符信息
auth_basic_user_file "/usr/local/nginx/pass"; //添加生成认证的密码文件
location / {
root html;
index index.html index.htm;
}
}
2.生成密码文件,创建用户及密码
# yum -y install httpd-tools
# htpasswd -c /usr/local/nginx/pass admin //创建用户
New password:654321
Re-type new password:654321
Adding password for user admin
# htpasswd /usr/local/nginx/pass jerry //追加用户,不使用-c选项
New password:123456
Re-type new password:123456
Adding password for user jerry
# cat /usr/local/nginx/pass //查看授权的用户
3.重启Nginx,加载配置文件
# /usr/local/nginx/sbin/nginx -s reload //重新加载配置文件
4.客户端测试
# firefox http://192.168.4.5 //输入密码后可以访问
结束