# Limit request count within set time

The Page Rules drop-down list contains a variety of classified actions. Select Limit Request Count from one of them “Request Limiting Action” to control the number of requests within a set period of time.

Different from the Limit Request Rate aimed at limiting the speed of requests, Limit Request Count means limiting the number of total requests.

Limit Request Count involves three parameters:

  1. Key Word: The default setting is using the IP address from the terminal as the key for counting;

  2. Reject Rate: If the number of requests within the set time range exceeds the threshold, 503 Error will be returned to the terminal;

  3. Time Window: Time range for second-based counting. A switch into a new time range leads to counting anew from zero.

Take this setting for example. It means that if the number of requests from a terminal surpasses one for each 60 seconds, 503 Error will be returned.

With no conditions imposed on this rule, just click the Create button on the bottom right-hand side.

Now, verify whether the limit rule works or not.

First, enter the Release page to synchronize this rule to nodes of all gateways.

With the release, Release can be viewed. No further explanation is necessary.

Then, open shell to simulate client-side access.

With the first access not restricted, 404 is returned as the page actually does not exist.


$ curl -i -H 'host: rewrite-rule-test.com' 52.43.45.19/404.html

HTTP/1.1 404 Not Found

Server: openresty+

Date: Mon, 21 Jan 2019 15:47:20 GMT

Content-Type: text/html

Content-Length: 166

Connection: keep-alive

<html>

<head><title>404 Not Found</title></head>

<body bgcolor="white">

<center><h1>404 Not Found</h1></center>

<hr><center>openresty</center>

</body>

</html>

Send the same request again to see whether 503 will be returned as expected:


$ curl -i -H 'host: rewrite-rule-test.com' 52.43.45.19/404.html

HTTP/1.1 404 Not Found

Server: openresty+

Date: Mon, 21 Jan 2019 15:47:21 GMT

Content-Type: text/html

Content-Length: 166

Connection: keep-alive

<html>

<head><title>404 Not Found</title></head>

<body bgcolor="white">

<center><h1>404 Not Found</h1></center>

<hr><center>openresty</center>

</body>

</html>

Sure enough, 503 Error is returned following the second request, indicating the above rule has worked.