1.安装 htpasswd 工具
1 | [root@uuu ~]# yum -y install httpd-tools |
1 2 3 4 | [root@uuu ~]# htpasswd -c /usr/local/src/nginx/passwd coderschool New password: Re-type new password: Adding password for user coderschool |
1 2 | [root@uuu ~]# cat /usr/local/src/nginx/passwd coderschool:$apr1$DhlW8hIu$BXyCQ7hiEos1DiqgwEYcZ1 |
2.修改 nginx 配置文件
1 2 3 4 5 6 7 8 9 10 11 12 | server { listen 80; server_name localhost; ....... #新增下面两行 auth_basic "Please input password"; #这里是验证时的提示信息 auth_basic_user_file /usr/local/src/nginx/passwd; location /{ ....... } |
1 2 3 4 | [root@uuu sbin]# ./nginx -t nginx: the configuration file /usr/local/src/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/src/nginx/conf/nginx.conf test is successful [root@uuu sbin]# ./nginx -s reload |
3.htpasswd选项参数
1 2 3 4 | htpasswd [-cmdpsD] passwordfile username htpasswd -b[cmdpsD] passwordfile username password htpasswd -n[mdps] username htpasswd -nb[mdps] username password |
htpasswd例子
1 | htpasswd -bc ./.passwd tonyzhang pass |
1 | htpasswd -b ./.passwd onlyzq pass |
1 | htpasswd -nb tonyzhang pass |
1 | htpasswd -D .passwd tonyzhang |
1 2 | htpasswd -D .passwd tonyzhang htpasswd -b .passwd tonyzhang pass |
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:http://hqyman.cn/post/1823.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~