@yanglt7
2018-10-13T12:14:46.000000Z
字数 1448
阅读 606
Web集群实战
location / {
auth_basic "ylt test";
auth_basic_user_file /application/nginx/conf/htpasswd;
}
#comment
name 1: passwd1
name 2: passwd2: comment
#www virtualhost by ylt
server {
listen 80;
server_name yangyangyang.org;
location / {
root html/www;
index index.html index.htm;
auth_basic "ylt test";
auth_basic_user_file /application/nginx/conf/htpasswd;
}
access_log logs/access_www.log main gzip buffer=32k flush=5s;
}
注:
/application/nginx/conf/htpasswd :用于设置认证的密码文件,即用户输入账户密码后,Nginx 会到这个文件中对比用户的输入是否正确。
获取 htpasswd 设置账户和密码
[root@ylt001 conf]# yum -y install httpd
[root@ylt001 conf]# which htpasswd
/usr/bin/htpasswd
[root@ylt001 ~]# htpasswd -bc /application/nginx/conf/htpasswd ylt 123456
Adding password for user ylt
[root@ylt001 ~]# chmod 400 /application/nginx/conf/htpasswd
[root@ylt001 ~]# chown nginx /application/nginx/conf/htpasswd
[root@ylt001 ~]# cat /application/nginx/conf/htpasswd
ylt:$apr1$wBWFORSP$h788WViX.soK184uaBtr6/
[root@ylt001 ~]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.14.0//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.14.0//conf/nginx.conf test is successful
[root@ylt001 ~]# /application/nginx/sbin/nginx -s reload
身份认证窗口
通过验证后的浏览器内容
未通过验证的浏览器报错