Rejected upload returns 413, modify program limit first or modify gateway limit first
When an attachment upload is rejected and returns 413, should you first modify the limit in the program or the limit at the gateway layer? Modify the gateway layer first. The 413 status code is the entry layer response for 'request body too large'—the gateway stops reading the request header and body at that point, and the request never reaches the program. No matter how wide the limit in the program is, it won't take effect. You can refer to the original text in the gateway document: The default limit for the request body is one megabyte, and when the size of the request exceeds the configured value, the 413 status code is returned to the client, and the document explicitly states that the browser cannot correctly display this error.
What layer does the 413 indicate that the request stopped at?
Stop at the 'Read Request' layer. Common layers at this level include: the reverse proxy in front of the site, CDN or edge node, gateway configuration at the container entry, and the rules configured for the site in the panel.
There are two criteria for judgment. One is the response source: 413 returned by whom, where the log falls - there is no such request in the program access log, which means it is intercepted at the entry layer. The other is the error body form: the entry layer returns its own default error page, which is different in style from the error page within the program.
Check these two before making any configuration changes. Skipping this step and directly modifying the program restrictions is the most common invalid operation in this type of issue: restart after changing, upload again, and it is still 413.
Why does the browser only show a connection error
The phrase 'The browser cannot correctly display this error' in the document refers to the actual phenomenon: when the user uploads halfway, the page only gives a vague failure prompt, and it is not clear that it is a volume problem.
This has two impacts on troubleshooting. First, user feedback usually won't say 'return 413', but 'it can't be uploaded', so you need to check the server status code yourself; second, the response received by the front-end script may be incomplete, and relying on interface prompts for location is unreliable.
By the way, here's a common misjudgment: this kind of failure looks like a timeout or a network disconnection. The difference lies in the size - if a smaller file can be uploaded successfully, it's a limit issue rather than a link issue.
The comparison and modification order of the three-tier restrictions
The upload and import restrictions within the site are usually distributed in three layers, each managing different things:
| Level | What does it manage? | Typical over-limit performance | Modification order |
|---|---|---|---|
| Entry and gateway layer | The limit of the entire request body | Return 413, no program log record | Change this layer first |
| Program execution layer | Limit of individual file and form field | Request comes into the application and returns business error prompt | Check this layer again |
| Business function layer | Self-limit of certain actions, such as import package size | Task fails and gives a reason | Adjust according to functional requirements |
The reason why the order cannot be reversed is very simple: the upper layer has not passed, and the lower layers have not been executed. In the three layers, as long as one layer is smaller than the target value, the actual available upper limit is that smaller value.
When making changes, configure according to the 'target volume reserve': the value of the entry layer should be greater than the program layer, and the value of the program layer should be greater than the value needed for a single operation in the business layer. The reversed configuration will bring a phenomenon that is very difficult to describe - small files are normal, and large files report application layer errors, looking like a program bug.
The actual practice when importing large files in batches
AnQiCMS supports batch document import, which can be done through ZIP compressed packages and Excel spreadsheets in two ways. When importing large compressed packages, the layers above are the ones that need to pass through.
There are four methods available, arranged from low to high cost:
Firstly, unpack. Cut into multiple smaller packages by category or time and import them in stages. No configuration is required, and it will not raise the upper limit of the entry layer.
Secondly, compress the content first and then package. Attachments and images occupy most of the package body. Before importing, upload the resources that do not need to be retained in the package separately through media upload, and the package body will be much smaller.
The third is to relax the upper limit of the entry layer. Confirm the need to support large package import for a long time before changing, and after changing, check the value of the program layer at the same time, adjusting both layers together has meaning.
The fourth is to submit in batches through the interface. AnQiCMS provides the /api/import/archive document content import interface, and also supports querying whether it exists by title, submitting in batches by item or in small batches in batch scenarios, the lowest affected by the limit may be the lowest.
The deployment form will affect which configuration: AnQiCMS's deployment methods include Baota panel one-click deployment, LNMP command line deployment, and Docker image, the service listens to port 8001 by default, and there is usually a reverse proxy in front of the site. For panel deployment, the site entry is limited to the panel's site configuration; for image plus self-built proxy, it is limited to the configuration in the front-end gateway; only when the service port is exposed directly, it is mainly limited by the program itself.
After the modification, do a real test: take a file slightly smaller than the target value to go through the entire process, not just look at the configuration.
Common questions
Is setting the limit to zero equivalent to removing the restriction?Setting zero in the document means that no request body check is performed, but this does not mean that the subsequent layers also do not check: constraints at the program and business layers still exist. Moreover, not checking the size of the request body will leave the memory and disk pressure to the application to bear, and it is not recommended to configure it this way for public network entry.
Why is it still failing after changing the configuration?There are three possibilities: the object changed is not the current effective one (common in multi-site or container scenarios), there is still one layer of the CDN in front or the edge node, and the program restart did not take effect. Try using a file that is just over the limit layer by layer, and you can locate which layer has not been changed properly.
Is there a relationship between upload limits and security?Yes. The limit at the entry layer is also the first control for slow large packets and resource usage. When releasing, give the value according to actual needs, do not raise it too high at once.
When there are many images, can the limit only be increased?Not necessarily. Media upload or batch processing through the interface can avoid large packets, and increasing the limit should be a last resort rather than the first action.