Nginx is working as a load balancer but not applying rate limiting. It does not matter what rate I set it to in the 'limit_req_zone' directive, it is completely ignored. I want requests from /api/notification/getnotifications (as shown below) to be rate limited for the same ip.
I have a simple server configuration that sends traffic to two servers through upstream.
What could I be doing wrong?
This is my configuration file.
limit_req_zone $binary_remote_addr zone=zonenot:15m rate=1r/m;
log_format upstreamlog '$server_name to: $upstream_addr [$request] '
'upstream_response_time $upstream_response_time '
'msec $msec request_time $request_time'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent" "$http_x_forwarded_for"';
upstream lbfrontend {
least_conn;
# frontendservers
server xxx.xxx.xxx:4000;
server kkk.kkk.kkk:4000;
}
upstream lbbackend {
least_conn;
# backendservers
server xxx.xxx.xxx:2000;
server kkk.kkk.kkk:2000;
}
server {
listen 80;
server_name xxx.xxx.xxx;
access_log /var/log/nginx/access.log upstreamlog;
location / {
proxy_pass http://lbfrontend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /api/notification/getnotifications {
limit_req zone=zonenot;
proxy_pass http://lbbackend;
}
location ^~ /api/ {
proxy_pass http://lbbackend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…