Nginx http://www.aliyun.com/zixun/aggregation/38609.html "> access control
1.Nginx ID Card Verification
#cd/usr/local/nginx/conf
#mkdir htpasswd
/usr/local/apache2/bin/htpasswd-c/usr/local/nginx/conf/htpasswd/tongji Linuxtone
#添加用户名为linuxtone
New Password: (enter your password here)
Re-type New Password: (enter your password again)
Adding password for user
http://count.linuxtone.org/tongji/data/index.html (Directory exists/data/www/wwwroot/tongji/data/directory)
The next configuration is placed in the virtual host directory, which prompts for http://count.linuxtone/tongji/when Access is available:
Location ~ ^/(Tongji)/{
Root/data/www/wwwroot/count;
Auth_basic "Lt-count-tongji";
Auth_basic_user_file/usr/local/nginx/conf/htpasswd/tongji;
}
2.Nginx prevents access to files of a certain type.
For example, Nginx access to *.txt files is prohibited, as follows.
Location ~*. (Txt|doc) $ {
if (-f $request _filename) {
Root/data/www/wwwroot/linuxtone/test;
#rewrite ... can be redirected to a URL
Break;
}
}
Method 2:
Location ~*. (Txt|doc) ${
Root/data/www/wwwroot/linuxtone/test;
Deny all;
}
Instance:
Prohibit access to a directory
Location ~ ^/(INF)/{
Deny all;
}
3. Using Ngx_http_access_module to restrict IP access
Location/{
Deny 192.168.1.1;
Allow 192.168.1.0/24;
Allow 10.1.1.0/16;
Deny all;
}
See more Wiki:http://wiki.codemongers.com/nginxhttpaccessmodule#allow