nginx 配置身份驗證 http_auth_basic_module


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM