編輯檔案 /usr/local/nginx/conf/nginx.conf
for http 模組
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
location / { satisfy any; # satisfy 滿足條件 # satisfy [all | any] # satisfy all => 下列條件都要滿足 # satisfy any => 下列條件只要任一滿足就可以 # 此處用到 http_access_module 及 http_auth_basic_module 兩個 # 所以設定為any~任一滿足即可 root html; index index.html index.htm; # ngx_http_access_module # 允許 10.201.80.107 瀏覽 allow 10.201.80.107; # 其它來源不允許瀏覽 deny all; # 其它來源使用帳密取得權限 # ngx_http_auth_basic_module auth_basic "Restricted Area"; # 設定跳出輸入帳號、密碼視窗的標題 auth_basic_user_file /usr/local/nginx/conf/.htpasswd; # 設定user file位置為/usr/local/nginx/conf/.htpasswd } |
安裝 apache2-utils
1 |
apt-get install apache2-utils |
產生 htpasswd 檔案
1 2 3 4 5 6 |
# 第一次請加 -c # htpasswd -c [user file位置] [帳號] htpasswd -c /usr/local/nginx/conf/.htpasswd tdg # 非第一次使用不加 -c # htpasswd [user file位置] [帳號] htpasswd /usr/local/nginx/conf/.htpasswd tdg |
reload nginx conf就可以了~