我试图实现与nginx的(V1.6.2)一个简单的速率限制系统nginx的limit_req不起作用
网站可用/ mysite.com:
limit_req_zone $binary_remote_addr zone=myzone:10m rate=2r/m;
server {
listen 80;
server_name mysite.com;
root /var/www/vhosts/mysite.com;
error_log [..];
access_log [..];
include conf.d/php-fpm.conf;
location =/{
limit_req zone=myzone burst=3 nodelay;
index index.html;
}
location/{
try_files $uri =404;
}
location ^~ /pages {
include conf.d/php-fpm.conf;
internal;
}
location = /email {
rewrite ^(.*)$ /pages/email.html;
}
location = /email/subscribe {
limit_req zone=myzone burst=2 nodelay;
rewrite ^(.*)$ /pages/email.php?action=subscribe;
}
location ~ /api {
limit_req zone=myzone burst=5 nodelay;
rewrite ^(.*)$ /pages/api.php;
}
}
的conf。 d/PHP-fpm.conf:
location ~ \.php$ {
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
nginx.conf: 没有什么有趣的,只有
include sites-enabled/*;
限速/
工作正常。如果我对此页面提出太多请求,则会收到错误503。
问题:/email/subscribe
,/api
和/api/test
都没有速率限制,我不知道为什么。它必须与rewrite
做些什么,但是问题是什么?
任何想法?我尝试了一切!
请注意:我更改了文件名和URL端点。
你已经从配置中删除了太多 – 2015-02-09 17:51:10
我不这么认为。除了server_name之外没有其他的东西.. – 2015-02-09 17:53:22
那么,你的'/ test'位置重写为'/ test.txt',并且该文件与'location =/test'不匹配,所以它由其他位置(或者_default_位置),它显然不包含'limit_req'指令。 – 2015-02-09 18:01:34