用户认证

)修改配置文件

[root@proxy ~]# 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)生成密码文件,创建用户及密码

[root@proxy ~]# yum -y install  httpd-tools
[root@proxy ~]# htpasswd -c /usr/local/nginx/pass   tom        //创建密码文件
New password: 
Re-type new password: 
Adding password for user tom
[root@proxy ~]# htpasswd  /usr/local/nginx/pass   jerry      //追加用户,不使用-c选项
New password: 
Re-type new password: 
Adding password for user jerry
[root@proxy ~]# cat /usr/local/nginx/pass

3)重启Nginx服务

[root@proxy ~]# /usr/local/nginx/sbin/nginx -s reload    //重新加载配置文件 

 

posted @ 2018-12-28 20:52  Ray_chen  阅读(173)  评论(0编辑  收藏  举报