[关闭]
@yanglt7 2018-10-13T12:14:46.000000Z 字数 1448 阅读 606

【Web 集群实战】11_Nginx 访问认证

Web集群实战


配置参数:

  1. location / {
  2. auth_basic "ylt test";
  3. auth_basic_user_file /application/nginx/conf/htpasswd;
  4. }
  1. #comment
  2. name 1: passwd1
  3. name 2: passwd2: comment

配置示例

  1. #www virtualhost by ylt
  2. server {
  3. listen 80;
  4. server_name yangyangyang.org;
  5. location / {
  6. root html/www;
  7. index index.html index.htm;
  8. auth_basic "ylt test";
  9. auth_basic_user_file /application/nginx/conf/htpasswd;
  10. }
  11. access_log logs/access_www.log main gzip buffer=32k flush=5s;
  12. }

注:

  1. [root@ylt001 conf]# yum -y install httpd
  2. [root@ylt001 conf]# which htpasswd
  3. /usr/bin/htpasswd
  1. [root@ylt001 ~]# htpasswd -bc /application/nginx/conf/htpasswd ylt 123456
  2. Adding password for user ylt
  3. [root@ylt001 ~]# chmod 400 /application/nginx/conf/htpasswd
  4. [root@ylt001 ~]# chown nginx /application/nginx/conf/htpasswd
  5. [root@ylt001 ~]# cat /application/nginx/conf/htpasswd
  6. ylt:$apr1$wBWFORSP$h788WViX.soK184uaBtr6/
  1. [root@ylt001 ~]# /application/nginx/sbin/nginx -t
  2. nginx: the configuration file /application/nginx-1.14.0//conf/nginx.conf syntax is ok
  3. nginx: configuration file /application/nginx-1.14.0//conf/nginx.conf test is successful
  4. [root@ylt001 ~]# /application/nginx/sbin/nginx -s reload

身份认证

身份认证窗口

通过认证

通过验证后的浏览器内容

未通过验证的浏览器报错

未通过验证的浏览器报错

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注