由于nginx版本比较老,0.8X所以不能使用新的限制语法。要求对www.wdzzz.com 限制下载200K,老的语法如下:
在http段添加:
limit_zone one $binary_remote_addr 10m;
增加全局限速:
server { location / { limit_conn one 1; limit_rate 100k; } } } /usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -s reload
测试限速竟然无效,经过查找资料发现限速定义在子配置文件的server段生效
# cat vhosts/www.wdzzz.com.conf server { listen 80; server_name www.wdzzz.com; index index.php index.html; root /data/httpd/www.wdzzz.com; limit_rate 200k .....
从新加载,测试生效。
需求:配置两个虚拟目录:
www.wdzzz.com/kk1/ 和 www.wdzzz.com/kk2/
www.wdzzz.com/kk2/ 限速200K
www.wdzzz.com/kk3/ 限速100K
修改配置文件,添加如下:
server { listen 80; server_name www.wdzzz.com; index index.php index.html; root /data/httpd/www.wdzzz.com; location ~ \.(gif|jpg|jpeg|png|bmp|ico|xml|swf|mp3)$ { expires 10d; } location /{ add_header 'Access-Control-Allow-Origin' 'http://http://wdzzz.ckl.com'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET'; } location ^~ /kk2 { alias /data/httpd/www.wdzzz.com; index index.php index.html; limit_rate 200k; } location ^~ /kk3 { alias /data/httpd/www.wdzzz.com; index index.php index.html; limit_rate 100k; }
从新加载配置文件,测试生效!