有時(shí)候我們通過(guò)nginx搭建了一臺(tái)文件服務(wù)器, 一般來(lái)講是公開(kāi)的, 但我們又希望該服務(wù)器不讓他人看到, 有人可能會(huì)搭建一個(gè)登錄系統(tǒng), 但是太麻煩, 也沒(méi)太大必要, 比較簡(jiǎn)單的做法是配置Basic Auth登錄認(rèn)證
1. 確定你安裝了httpd-tools
yum install httpd-tools -y
2. 創(chuàng)建授權(quán)用戶和密碼
htpasswd -c -d /usr/local/openresty/nginx/conf/pass_file magina
這個(gè)配置文件存放路徑可以隨意指定, 這里我指定的是nginx配置文件目錄, 其中magina是指允許登錄的用戶名, 這個(gè)可以自定義
3. 配置Nginx
大致配置如下:
server { listen 80; server_name res.yinnote.com; auth_basic "登錄認(rèn)證"; 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 是認(rèn)證的配置, 注意密碼文件的路徑一定是上面生成的
4. 使用
# 瀏覽器中使用直接在瀏覽器中輸入地址, 會(huì)彈出用戶密碼輸入框, 輸入即可訪問(wèn)# 使用 wgetwget --http-user=magina --http-passwd=123456 http://res.yinnote.com/xxx.zip# 使用 curlcurl -u magina:123456 -O http://res.yinnote.com/xxx.zip
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選