Nginx – limit_req causing 503 Service Unavailable

nginx

I'm frequently getting 503 Service Unavailable when I have limit_req turned on. On my logs:

[error] 22963#0: *70136 limiting requests, excess: 1.000 by zone "blitz", client: 64.xxx.xxx.xx, server: dat.com, request: "GET /id/85 HTTP/1.1", host: "dat.com"

My nginx configuration:

limit_req_zone $binary_remote_addr zone=blitz:60m rate=5r/s;
limit_req   zone=blitz;

How do I resolve this issue. Isn't 60m already big enough? All my static files are hosted on a amazon s3.

Best Answer

503 Service unavailable is returned whenever you hit the limit requests. From the limitreq documentation:

If the rate of requests exceeds the rate configured for a zone, request processing is delayed such as that they are processed at a defined rate. Excessive requests are delayed until their number exceeds the defined number of bursts. When exceeded, the request is terminated with an error 503 (Service Temporarily Unavailable). By default, the number of bursts is equal to zero.

You did not specify a burst rate, so whenevery you do more than 5 requests per second, you will get HTTP 503 Service Unavailable in return. Try raising your limit or specify a higher burst rate.

Related Topic