When the interface is being attacked, should the speed limit be configured at the gateway layer or in the program?

📅 October 10, 2026 👁️ 11

When the site interface is flooded with a large number of requests, where should the rate limit be set, at the Web server gateway layer or in the program? Both layers are set, but they block different things: the gateway layer limits the request rate based on the source address, and the request is dropped before it enters the program; the program layer knows who the caller is and what action they are taking, and can set tiers for interfaces such as login, comment, and background. The judgment sequence is to first see which type of interface is being flooded - if it is the entire site page, use the gateway layer, and if it is a specific business action, limit it according to the action in the program layer.

What do the two layers of speed limiting block separately

The gateway layer's rate limiting dimension is by address: it counts the rate by the source address and rejects when exceeding. It does not care which business the request belongs to, nor does it matter whether the caller is logged in. The benefit is that it does not consume application resources, but the drawback is that normal users under the same exit address may be limited together.The program layer can read identity and actions, and can set search, message, and background login thresholds for the same address separately. The cost is that each request has to enter the program before counting starts.In the official description, the loading speed and concurrent承载 of this type of site is an advantage over traditional PHP systems, capable of handling about 5 million PVs on a single machine - but this is a capacity description and cannot replace speed limits: a large capacity does not mean that abnormal traffic should not be restricted.

How to write the two parameters of rate and burst volume

For example, with nginx's rate limiting module, the rule first declares a shared memory area, and then retrieves the key by dimension. The document specifies that the rate is expressed in requests per second (r/s);The burst quantity (burst) defaults to zero, which means that it cannot handle anything beyond the rate. The actual format is that the rate provides a stable line, while burst provides a temporary surplus that can pass without delay: when burst is zero, any instantaneous fluctuation will trigger a limit, and a normal user refreshing a little faster may be rejected;Provide a small burst, which means allowing short bursts. There is also a delay method where requests exceeding the rate are queued instead of being rejected directly, the document also states that requests exceeding the rate will be delayed until the number exceeds the maximum burst size, at which point they will be terminated with an error.

limit_req_zone $binary_remote_addr zone=api:10m rate=5r/s;
limit_req zone=api burst=10 nodelay;

Which error code should be returned for exceeding the limit

By default, a rejected request returns 503, and this status code can be changed in the example configuration with limit_req_status.The selection matters: 503 indicates temporarily unavailable, with a retry semantics that are clear, suitable for throttling; 429 is a specific request too many semantics, making it easier for the caller to recognize it as 'throttled' rather than 'service is down.'It is not recommended to return 500, as it will mix speed limits with program failures, misleading the troubleshooting direction. The default listening port within the site is 8001, and when the gateway is proxying in front, the speed limit return code should be set in the gateway configuration;Under the form that directly interacts with the program, the speed limit logic must be borne by the application itself. The deployment form determines where this parameter is written in the configuration document.

Which interfaces should be limited and which should not

Interface Type Suggested level Reason Risk of misfire
Search and filter Gateway + Program High cost, easy to be scanned by scripts Low
Leave comments and submit reviews Program Distinguish between login and user groups Low
Back-end login Program is the main one Need to judge according to account and action Low
Content images and static resources Be cautious of restrictions Multiple requests on the same page will interrupt loading due to speed limits High
Normal page Relaxed Affects user experience and crawling High

What should not be restricted is static resources and normal page browsing: the same page will request multiple images and styles concurrently. Tight control by address dimension will cause the page to be incomplete. The address segment of the crawling tool also needs to be reserved separately, otherwise speed limits will directly affect the inclusion and visibility of the content.

Common questions

Question: Is it enough to configure gateway speed limits?Answer: It is sufficient when it comes to brushing the entire site traffic. For brushing volume of a specific business interface, the gateway cannot control the specific action by address dimension, and it depends on the program layer to categorize.

Ask: How much should burst be set to?Answer: Starting from the behavior of normal users: Allow a short burst without queuing, set the value so that normal refreshes are not rejected, there is no general value. After modification, observe the rejection rate and adjust accordingly.

Ask: How to see who was limited after speed limiting in the log?Answer: Look at the aggregation of the source address corresponding to the status code in the gateway access log, and judge whether it is a single address or a group of users from the same exit with the key of the speed limit area (default by source address).

Related articles

The website returns 502 when opened, check the program or the gateway layer first.

First, check who sent this response. 502 means that the gateway or proxy server received an invalid response from upstream, which means that the request reached the gateway and the gateway tried to forward it, but the problem is between the gateway and the program; if the gateway cannot get any response at all, it returns a 504 or similar. Troubleshooting follows three steps: bypass the gateway and directly connect to the source station port, check the gateway error logs, and check the program process and port listening. The deployment form determines which machine to perform these three steps.

2026-10-10

Don't want the page to appear in the search results, is it marked in the page or written in the exclusion rules in the file?

What needs to be blocked is whether it is crawling or indexing. The exclusion rules in the file block crawling, so content cannot be read if the page cannot be accessed; the exclusion tags in the page block indexing, on the premise that the page can be crawled. Simply writing file exclusion rules does not mean it will not be included: if a blocked page has external links pointing to it elsewhere, it may still be included in the index due to link information. To ensure it does not appear, use page-level tags and make sure they can be crawled and read; the site's robots configuration is responsible for file-level crawling control, and the two work in conjunction.

2026-10-10

Should we block AI crawling, is it written in the exclusion rules or opened up another channel?

When controlling AI-based scraping programs, the Robots exclusion rules express intent rather than enforcement: they are issued according to the path and program identifiers, and rely on the scraping party to comply voluntarily. They cannot control addresses that have already been linked out, nor are they access control. When enforcement is needed, the focus should be on server-side authentication and the paths not being publicly readable; to prevent content from being moved in one piece, there are also interference codes and anti-crawling measures. The three things should not be mixed into one layer.

2026-10-09

The optional section marked as optional in the model description file, when will it really be skipped?

In the site description file for large models, only the line writing the site name is necessary, and the rest of the paragraphs may be omitted; the entry line consists of a mandatory link followed by an optional colon and description. Optional paragraphs are provided for the convenience of the reader when the context is not long enough, and when skipped, they do not lose major information but secondary information, so the main link should be placed in non-optional paragraphs. This file within the station is automatically generated and kept synchronized by the content module.

2026-10-09

Why should the script execution permission be removed from the upload directory, and at which layer is it blocked

Because the file content in the upload directory comes from visitors, the path is a location that the server can read and access. The meaning of removing script execution permissions is: even if script files are written in, they will only be returned as static content and will not be executed as programs. This type of restriction is more suitable for doing path matching separately in Web server configurations, the rule is to take the longest prefix, and regular expressions are matched in the order of appearance, so a stable matching configuration needs to be written for the upload directory. After making the changes, check the backup to avoid mistakenly damaging normal attachment access.

2026-10-10

What steps should be taken to follow up on the WordPress 7.1.2 fix for unauthorized reading of local files on the enterprise site?

WordPress 7.1.2 is a security version released on September 22, 2026, which fixes a unauthorized attack issue: Under certain conditions, attackers can allow the page template to parse read local PHP files outside the active theme directory, and under certain environmental prerequisites, it can develop into remote code execution. The official severity level is critical, and the fix has been rolled back to the branch that is still receiving security fixes. For enterprise stations, follow the four steps of backup, upgrade, check entry, and file review.

2026-10-10

Why does the security upgrade announcement of the peer CMS still require clearing the cache and checking the files?

The security upgrade notification of the peer system often includes two requirements unrelated to the patch: delete the runtime cache directory after the upgrade and check if there are any abnormal files in the website directory. The reason is that the patch only closes the entrance and is not responsible for clearing the consequences that have already landed - there may be pages with old content left in the cache, and files uploaded may be left in the directory. The follow-up order should be to confirm the rollback first, then upgrade, and finally clear the cache and review the files.

2026-10-10

Can read which content in the station without logging in, whether to seal it off

According to the official manual, publicly available articles, pages, and categories on the site can be read through the interface by default, while encrypted content, internal users, custom types, and metadata require identity verification to access. The closure is not to shut down the interface as a whole, but to divide the exposed range by capability domain, collect permissions by user group, add confirmation steps to writing operations, and first test the visible surface with an unlogged request.

2026-10-10