安装 htpasswdnginx
yum -y install httpd-tools
设置用户名和密码文件,有一点须要注意htpasswd有效密码长度只有8位web
htpasswd -c /usr/local/nginx/conf/passwd cuber New password: Re-type new password: Adding password for user cuber
修改 nginx 配置文件算法
vi nginx.conf server { listen 80; server_name localhost; # ... # 新增两行 auth_basic "password"; auth_basic_user_file /usr/local/nginx/conf/passwd; location /{ # ... }
重启 nginxcurl
./nginx -t ./nginx -s reload
测试认证svg
curl http://user:passwd@127.0.0.1
htpasswd选项参数测试
htpasswd [-cmdpsD] passwordfile username htpasswd -b[cmdpsD] passwordfile username password htpasswd -n[mdps] username htpasswd -nb[mdps] username password
htpasswd命令选项参数说明加密
-c # 建立一个加密文件 -n # 不更新加密文件,只将htpasswd命令加密后的用户名密码显示在屏幕上 -m # 默认htpassswd命令采用MD5算法对密码进行加密 -d # htpassswd命令采用CRYPT算法对密码进行加密 -p # htpassswd命令不对密码进行进行加密,即明文密码 -s # htpassswd命令采用SHA算法对密码进行加密 -b # htpassswd命令行中一并输入用户名和密码而不是根据提示输入密码 -D # 删除指定的用户
同时输入用户名和密码url
htpasswd -cb /usr/local/nginx/conf/passwd user12 'passwd123'