linux就该这么学pdf免费下载
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
转载请注明:谷谷点程序 » Nginx访问控制的方法