有時候我們通過nginx搭建了一臺文件服務器, 一般來講是公開的, 但我們又希望該服務器不讓他人看到, 有人可能會搭建一個登錄系統, 但是太麻煩, 也沒太大必要, 比較簡單的做法是配置Basic Auth登錄認證
1. 確定你安裝了httpd-tools
yum install httpd-tools -y
2. 創建授權用戶和密碼
htpasswd -c -d /usr/local/openresty/nginx/conf/pass_file magina
這個配置文件存放路徑可以隨意指定, 這里我指定的是nginx配置文件目錄, 其中magina是指允許登錄的用戶名, 這個可以自定義
3. 配置Nginx
大致配置如下:
server { listen 80; server_name res.yinnote.com; auth_basic "登錄認證"; auth_basic_user_file /usr/local/openresty/nginx/conf/pass_file; autoindex on; autoindex_exact_size on; autoindex_localtime on; root /mnt/html/resource; index index.html index.php;}
其中 auth_basic 和 auth_basic_user_file 是認證的配置, 注意密碼文件的路徑一定是上面生成的
4. 使用
# 瀏覽器中使用直接在瀏覽器中輸入地址, 會彈出用戶密碼輸入框, 輸入即可訪問# 使用 wgetwget --http-user=magina --http-passwd=123456 http://res.yinnote.com/xxx.zip# 使用 curlcurl -u magina:123456 -O http://res.yinnote.com/xxx.zip
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
|
新聞熱點
疑難解答