ngx_http_auth_basic_module模塊實現訪問必須輸入用戶名和密碼 正確情況向訪問,這為我們一些重要資源訪問增添了一道安全鎖。
語法: auth_basic_user_file file;
默認值: —
配置段: http, server, location, limit_except
用戶密碼加密方式
http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
支持htpasswd等
htpasswd安裝
yum install httpd-tools -y
首次創建並加入
htpasswd -c ./user_passwd admin
會出現
New password:
Re-type new password:
Adding password for user admin
兩次密碼都正確情況下創建用戶成功
查看 cat user_passwd
繼續添加用戶
htpasswd user_passwd user2
或者 htpasswd -b user_passwd user3 123456
刪除一個用戶
[root@centos1 conf]# htpasswd -D user_passwd admin
nginx里配置 location /admin{ auth_basic "auth: "; auth_basic_user_file /usr/local/nginx/conf/user_passwd; }
然后重啟nginx
打開后台網址后顯示
不然會出現
401 Authorization Required