Nginx下配置Http Basic Auth保護目錄

來源:互聯網
上載者:User

標籤:password   訪問   ice   url   printf   服務   span   cal   name   

     nginx basic auth指令

文法:     auth_basic string | off;
預設值:     auth_basic off;
配置段:     http, server, location, limit_except

預設表示不開啟認證,後面如果跟上字元,這些字元會在彈窗中顯示。

文法:     auth_basic_user_file file;
預設值:     —
配置段:     http, server, location, limit_except

 

1. 下載這個Python檔案:http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py (nginx wiki裡推薦的)

chmod 777 htpasswd.py  #給檔案加上許可權./htpasswd.py -c -b htpasswd username password#-c為組建檔案 htpasswd為檔案名稱
-d 是以 crypt 加密
username為登入的名字 password為登入密碼

2.可以使用可以使用htpasswd,或者使用openssl建立密碼

# printf "ttlsa:$(openssl passwd -crypt 123456)\n" >>conf/htpasswd# cat conf/htpasswd ttlsa:xyJkVhXGAZ8tM

3.把htppasswd檔案放到nginx/conf檔案下面,編輯nginx.conf檔案

在location裡面加兩行:auth_basic     "password please";auth_basic_user_file  conf/htpasswd;

4.重啟Nginx服務

service nginx start

5.注意錯誤提醒:說明43行有錯

6.可以使用curl -v http://localhost 查看http返回的狀態代碼:401未經授權表示成功

 

7.在瀏覽器裡預設的訪問地址是http://localhost

 

Nginx下配置Http Basic Auth保護目錄

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.