當使用nginx的limit_req模塊,limit_req_zone有兩個變量,就會報錯。html
【nginx的limit_req模塊只能有一個變量,而Tenginx能夠支持多個,具體的能夠查看官網的模塊介紹,很坑,換了tenginx便可】node
http://www.ithov.com/linux/114606.shtml
http://nginx.org/en/docs/http/ngx_http_limit_req_module.htmllinux
nginx報錯:
[root@www ~]# /root/nginx_reload
nginx: [emerg] invalid number of arguments in "limit_req_zone" directive in /usr/local/nginx/conf/nginx.conf:52
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failednginx
limit_req需求:
同一IP來源同一URI 15r/m
同一IP來源 30r/m
http段:
geo $white_ip {
ranges;
default 0;
127.0.0.1-127.0.0.255 1;
192.168.168.1-192.168.168.254 1;
}
limit_req_zone $binary_remote_addr $uri zone=reqzone:20m rate=15r/m;
limit_req_zone $binary_remote_addr zone=req_ip:10m rate=30r/m;
limit_req_whitelist geo_var_name=white_ip geo_var_value=1;
server段:
location ~ ^/test/.*\.html {
limit_req zone=reqzone burst=5 nodelay;
limit_req zone=req_ip burst=5 nodelay;
proxy_pass http://WEB_APP;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
spa