
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 下載速度和并發(fā)速率
|
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.對上文件大小限制
主配置文件里加入如下,具體大小根據(jù)你自己的需做對應的調整。
|
client_max_body_size 10m; |
|