没有不值得去解决的问题,也没有不值得去学习的技术!

WordPress Tag Saving Failed: How an Nginx Rate Limit Rule Caused a 429 Error and How to Fix It

A prompt at the bottom of the page stating, "This response is not a valid JSON response."

Background

To enhance security on a WordPress site I maintain, I recently configured global rate limiting rules in Nginx. Shortly after applying the configuration, I found that I could not properly add or save tags while editing posts. 429 Too Many Requests and 400 Bad Request appeared frequently in the browser console and Nginx logs. After a step-by-step investigation, I identified the overly strict rate limiting rules as the culprit. This article documents the symptoms, troubleshooting process, solution, and verification steps in full, hoping to provide a reference for anyone encountering similar issues. Reference: 从单日126次504超时到彻底稳定:WordPress 1核2G服务器极限优化全记录(附全部实操命令)

1. Symptoms

When editing a post in the WordPress backend, attempting to add a new tag or save existing tags resulted in the following:

  1. The tag input box responded slowly, sometimes with no response after typing characters.
  2. A prompt appeared at the bottom of the page stating, “This response is not a valid JSON response.”
  3. Refreshing the page revealed that some tags had not been saved.
  4. The browser developer tools (Network tab) showed numerous requests to /wp-json/wp/v2/tags returning status codes 429 or 400.
A prompt at the bottom of the page stating, "This response is not a valid JSON response."
A prompt at the bottom of the page stating, “This response is not a valid JSON response.”

2. Nginx Rate Limiting Configuration (Problematic Configuration)

Inside the http block of the main configuration file nginx.conf:

Plaintext
# Global rate limit: 6 requests per second per IP, memory cache for 100,000 IPs
limit_req_zone $binary_remote_addr zone=site_limit:10m rate=6r/s;
# Maximum concurrent connections per IP: 20
limit_conn_zone $binary_remote_addr zone=conn_limit:10m;

At the beginning of the server block in the site virtual host configuration vhost/www.example.com.conf:

Plaintext
# Enable request rate limiting, burst buffer of 12, no delay
limit_req zone=site_limit burst=12 nodelay;
# Concurrent connection limit: 20
limit_conn conn_limit 20;
# Return 429 when limit is exceeded
limit_req_status 429;

3. Troubleshooting Process

1. Confirming if Rate Limiting Was Triggered

First, I checked the Nginx access logs to count the number of 429 status codes:

Bash
grep -c " 429 " /data/wwwlogs/www.example.com_nginx.log
# 输出:738

This indicated that the rate limiting rules were triggering extensively. But was the issue directly related to the tag API? I further filtered the 429 responses for the tag interface:

Bash
grep "/wp-json/wp/v2/tags" /data/wwwlogs/www.example.com_nginx.log | grep -c " 429 "
# 输出:28

Definitive proof: the tag REST API requests were being intercepted by rate limiting.

2. Monitoring Request Status in Real Time

I used tail -f to observe the live logs while operating the tags:

Bash
tail -f /data/wwwlogs/www.example.com_nginx.log | grep "/wp-json/wp/v2/tags"

Example output:

Plaintext
211.137.80.234 - - [05/Jun/2026:20:48:20 +0800] "POST /wp-json/wp/v2/tags?_locale=user HTTP/2.0" 429 177 "..."

Numerous 429 appeared, with multiple requests rejected per second.

3. Analyzing Why Tag Operations Trigger Numerous Requests

The WordPress block editor (Gutenberg) frequently calls the REST API when handling tags:

  • Searching tags: Every time a user types a character in the tag input box, a GET /wp-json/wp/v2/tags?search=xxx is sent.
  • Creating new tags: When a non-existent tag name is entered and loses focus, a POST /wp-json/wp/v2/tags is sent to create it.
  • Saving the post: Tag IDs are batch-associated upon submission.

When editing an article that already has 20 tags, the aforementioned requests might be sent 20 to 30 times within a few seconds. However, our rate limiting rule was set to 6 requests/second, allowing a maximum burst of 12 queued requests at any instant. Once exceeded, it directly returned 429.

Upon receiving 429 on the frontend, certain scripts would enter a retry loop (especially when the response body was not as expected), causing continuous retries of the same POST request from the same IP in the logs, further exacerbating the situation.

4. Why Were 400 Errors Also Present?

In the logs, we found that some requests returned 400. This is because:

  • When users quickly create new tags, the frontend might send multiple identical POST requests consecutively (for example, due to an imperfect debounce mechanism or network retries).
  • The WordPress REST API returns 400 when it receives duplicate tag names (indicating “this tag already exists” or “parameter error”).
  • This situation does not affect the final tag creation—the first request successfully creates the tag, and subsequent duplicate requests return 400, but the post can still be saved by associating the already created tag ID.

Therefore, the 400 errors are redundant responses caused by duplicate frontend requests, not the root cause of the save failure. The truly fatal issue is 429, because the requests are intercepted directly by Nginx and never even reach the WordPress application layer.

4. Solution

The essence of the problem was that the rate limiting threshold was too low to accommodate the request frequency required for normal editing operations. There are two solutions: increase the rate limiting parameters or exempt the REST API path from rate limiting. Considering configuration simplicity and the desire to retain some security protection, we chose to increase the parameters.

Modification Steps

  1. Edit the main configuration file to increase the rate:
Bash
   vi /usr/local/nginx/conf/nginx.conf

Change:

Plaintext
   limit_req_zone $binary_remote_addr zone=site_limit:10m rate=6r/s;

To:

Plaintext
   limit_req_zone $binary_remote_addr zone=site_limit:10m rate=30r/s;
  1. Edit the site configuration file to increase the burst buffer:
Bash
   vi /usr/local/nginx/conf/vhost/www.example.com.conf

Change:

Plaintext
   limit_req zone=site_limit burst=12 nodelay;

To:

Plaintext
   limit_req zone=site_limit burst=50 nodelay;

Optionally, increase the concurrent connection limit as well:

Plaintext
   limit_conn conn_limit 50;
  1. Restart Nginx:
Bash
service nginx restart

Tuning Notes

  • rate=30r/s: Allows an average of 30 requests per second, enough to cover the normal peak of tag operations (about 15 to 20 requests/second during fast typing) while still preventing brute-force attacks.
  • burst=50: Allows up to 50 requests to queue instantaneously, avoiding rate limit triggers caused by concurrent resource requests during page loads.
  • If server performance is robust, these can be further increased to 50r/s, burst=80.

5. Verification and Results

After applying the modifications, I went back to the WordPress backend to edit posts, add tags, and save. Observing the logs:

Bash
tail -f /data/wwwlogs/www.example.com_nginx.log | grep "/wp-json/wp/v2/tags"

429 no longer appeared; there were only a few successful 200 responses and occasional 400 (caused by duplicate frontend requests, which did not affect the final save). The post tags saved successfully, and the issue was resolved.

No more 429 errors, only a few 200 successful responses and occasional 400s (caused by duplicate frontend requests, which do not affect the final save). The post tags saved successfully, and the issue is resolved.

6. Lessons Learned and Recommendations

  1. Rate limiting is a double-edged sword: Proper configuration can defend against CC attacks and brute-force cracking, but thresholds set too low will disrupt normal user operations, especially in modern editors that rely on frequent API calls.
  2. Monitor and test: Before applying rate limiting rules, it is recommended to run in a lenient mode and observe access logs, adjusting rate and burst based on actual business request frequencies.
  3. Granular rate limiting: If you wish to retain strict rate limiting, you can apply different strategies to different paths. For example:
  • Maintain rate=6r/s for /wp-login.php, /xmlrpc.php.
  • Set a higher threshold or completely exempt /wp-json/*. Example configuration snippet:
Plaintext
   location /wp-json/ {
       limit_req zone=api_limit burst=100 nodelay;
       # Other configurations
   }
  1. Distinguish between 429 and 400: 429 is returned by the rate limiting middleware, meaning the request never reached the application layer; 400 is returned by the application layer and is typically related to the request content (such as duplicate submissions or parameter validation failures). When troubleshooting, first confirm whether 429 exists, as it causes more severe functional disruption.
  2. Document changes: After every Nginx configuration modification, it is recommended to record the changes and date for future traceability.

7. Conclusion

A seemingly complex tag save failure issue was ultimately rooted in overly conservative Nginx rate limiting parameters. By analyzing access logs, identifying 429 responses, and adjusting the rate limiting thresholds, the problem was resolved with minimal cost. I hope the troubleshooting approach and solution in this article prove helpful for your WordPress operations. If you are experiencing similar 429 issues, consider checking your Nginx rate limiting configuration first—it might save you a lot of effort.

Appendix: Common Troubleshooting Commands Cheat Sheet

  • Count 429s: grep -c " 429 " /path/to/access.log
  • Monitor tag API in real time: tail -f access.log | grep "/wp-json/wp/v2/tags"
  • Test configuration syntax: nginx -t

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系