
1.Nginx 身份证密码验证
|
#cd /usr/local/nginx/conf #mkdir htpasswd /usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/home lenfeng #添加用户名为lenfeng New password: (此处输入你的密码) Re-type new password: (再次输入你的密码) Adding password for user |
http://it./home/data/index.html(目录存在/www/wwwroot/home/data/目录下)
将下段配置放到虚拟主机目录,当访问http://it./home/即提示要密验证:
|
location ~ ^/(home)/ { root /www/wwwroot/count; auth_basic "LT-COUNT-Home"; auth_basic_user_file /usr/local/nginx/conf/htpasswd/home; } |
2.禁止Nginx 对某类型的文件访问
如,在Nginx下禁止对*.txt文件的访问,配置方法如下:
|
location ~* \.(txt|doc)$ { if (-f $request_filename) { root /data/www/wwwroot/lenfeng/test; #rewrite …..可以重定向到某个URL break; } } |
第二种方法:
|
location ~* \.(txt|doc)${ root /data/www/wwwroot/lenfeng/test; deny all; } |
第三种方法:禁止访问某个目录
|
location ~ ^/(WEB-INF)/ { deny all; } |
3.用ngx_http_access_module限制ip对nginx的访问
|
location / { deny 192.168.1.1; allow 192.168.1.0/24; allow 10.1.1.0/16; deny all; } |
4.限制Nginx 下载速度和并发速率
|
limit_zone lenfeng $binary_remote_addr 10m; server { listen 80; server_name down.lenfeng.com; index index.html index.htm index.php; root /data/www/wwwroot/down; #Zone limit location / { limit_conn lenfeng 1; limit_rate 20k; } .......... } //只允许客户端一个线程,每个线程20k. |
【注】limit_zone lenfeng $binary_remote_addr 10m; 这个可以定义在主的
5.Nginx 跟Apache一样有目录列表权限
|
location / { autoindex on; } |
6.对上文件大小限制
主配置文件里加入如下,具体大小根据你自己的需做对应的调整。
|
client_max_body_size 10m; |
|