Nginx实战之让用户通过用户名密码认证访问web站点

 

1、Nginx实战之让用户通过用户名密码认证访问web站点

[root@master ~]# vim /usr/local/nginx/conf/extra/www.conf
    server { 
         listen       80;  //监听端口为80 
         server_name  www.test.com;  //虚拟主机网址 
          location / { 
                root   html/;  //虚拟主机网站根目录 
                index  index.html index.htm;  //虚拟主机首页 
                auth_basic "secret";  //虚拟主机认证命名 
                auth_basic_user_file /usr/local/nginx/passwd.db; //虚拟主机用户名密码认证数据库 
            } 
            location /status { 
                    stub_status on;  //开启网站监控状态 
                    access_log /usr/local/nginx/logs/www1_status.log; //监控日志 
                    auth_basic "NginxStatus"; } 
        }

  

2.通过htpasswd命令生成用户名及对应密码数据库文件
[root@master extra]# htpasswd -c /usr/local/nginx/passwd.db admin
New password: 
Re-type new password: 
Adding password for user admin
[root@abcdocker extra]# chmod 400 /usr/local/nginx/passwd.db 
[root@abcdocker extra]# chown nginx.  /usr/local/nginx/passwd.db
[root@abcdocker extra]# cat /usr/local/nginx/passwd.db 
admin:$apr1$w3RqjNXW$mSiazU7t2THQqo3LrPmlP/

  

posted @ 2017-05-10 16:56  純黑色  阅读(633)  评论(0编辑  收藏  举报