安裝密碼生成工具
yum -y install httpd-tools
生成用戶和密碼文件
[root@localhost nginx]# htpasswd -c /usr/local/nginx/password web01
New password: 這里輸入密碼
Re-type new password: 再次輸入密碼
Adding password for user web01
參數說明:
web01
是自定義用戶
password
是密碼文件
回車后,輸入用戶名的密碼,就完成了文件的生成。
查看生成的用戶和密碼
cat /usr/local/nginx/password
修改nginx配置
server {listen 80;...# 驗證時的提示信息auth_basic "請輸入用戶和密碼";# 認證文件auth_basic_user_file /usr/local/nginx/password;location / {}}
刪除用戶和密碼
#-D 刪除指定的用戶
htpasswd -D /usr/local/nginx/password username