Nginx HTTP://www.aliyun.com/zixun/aggregation/38609.html">存取控制
1.Nginx 身份證驗證
#cd /usr/local/nginx/conf
#mkdir htpasswd
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/tongji linuxtone
#添加使用者名為linuxtone
New password: (此處輸入你的密碼)
Re-type new password: (再次輸入你的密碼)
Adding password for user
HTTP://count.linuxtone.org/tongji/data/index.html(目錄存在/data/www/wwwroot/tongji/data/目錄下)
將下段配置放到虛擬主機目錄,當訪問HTTP://count.linuxtone/tongji/即提示要密驗證:
location ~ ^/(tongji)/ {
root /data/www/wwwroot/count;
auth_basic "LT-COUNT-TongJi";
auth_basic_user_file /usr/local/nginx/conf/htpasswd/tongji;
}
2.Nginx 禁止訪問某類型的檔.
如,Nginx下禁止訪問*.txt檔,配置方法如下.
location ~* \. (txt|doc)$ {
if (-f $request_filename) {
root /data/www/wwwroot/linuxtone/test;
#rewrite .....可以重定向到某個URL
break;
}
}
方法2:
location ~* \. (txt|doc)${
root /data/www/wwwroot/linuxtone/test;
deny all;
}
實例:
禁止訪問某個目錄
location ~ ^/(WEB-INF)/ {
deny all;
}
3.使用ngx_HTTP_access_module限制ip訪問
location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
deny all;
}
詳細參見wiki: HTTP://wiki.codemongers.com/NginxHttpAccessModule#allow