整體思路
- 將nginx作為下載器使用,可以將資源傳至特定目錄下,對外提供nginx的IP即可下載;
- 其中最重要的引數為“autoindex on”;
- 將nginx下載器加密,以賬號密碼的方式進行訪問
創建下載目錄
- 此目錄為下載目錄,可以將需要下載的東西傳至該目錄,
tree /opt/nginx/download/
/opt/nginx/download/
├── test1
├── test2
└── test3
0 directories, 3 files
修改nginx檔案
location / {
root download;
autoindex on;
#index index.html index.htm;
}
- autoindex on引數:目錄瀏覽下載功能開啟;
驗證
- 點擊即可下載

加密
yum -y install httpd-tools
htpasswd -c /opt/nginx/passwd/user1 user1
#輸入密碼
#確認密碼
- /opt/nginx/passwd/user1是密碼存放路徑
- user1是用戶名稱
修改nginx組態檔
location / {
root download;
autoindex on;
auth_basic "Please input password"; #這里是驗證時的提示資訊
auth_basic_user_file /opt/nginx/passwd/user1;
重啟
nginx -s reload
- auth_basic_user_file:啟用該路徑下用戶認證
驗證
輸入賬號密碼之后方可訪問

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/293323.html
標籤:其他
