# Trying to rate limit 404 errors by IP

**URL:** <https://community.nginx.org/t/trying-to-rate-limit-404-errors-by-ip/4903>\
**Category:** NGINX\
**Tags:** rate-limit, ip\
**Created:** [June 4, 2025, 10:56pm UTC](https://community.nginx.org/t/trying-to-rate-limit-404-errors-by-ip/4903 "2025-06-04T22:56:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![j3j5](https://drob5swvtjqxg.cloudfront.net/user_avatar/community.nginx.org/j3j5/32/2286_2.png) [@j3j5](https://community.nginx.org/u/j3j5)\
**Post date:** [June 4, 2025, 10:56pm UTC](https://community.nginx.org/t/trying-to-rate-limit-404-errors-by-ip/4903/1 "2025-06-04T22:56:10Z")

</div>

**My issue:**  
I’m trying to rate limit requests to my server that result on 404 errors because I’ve got some malicious crawlers crashing my database trying to find wordpress endpoints, accesible git repositories and some other typical endpoints which do not exist on my site, but require a db check due to the dynamic nature of my app.

**How I encountered the problem:**  
I’ve tried to follow the documentation in order to add rate limiting into 404 pages but I haven’t been able to make it work. For some reason it seems the rate limiter module does not run for errors. As you can see on the playground snippet below, `$limit_req_status` doesn’t even get populated. I couldn’t find anything on the docs that would explain this.

**Solutions I’ve tried:**  
[https://tech-playground.com/snippet/thankful-scorpion-of-success/](https://tech-playground.com/snippet/thankful-scorpion-of-success/)

Any help will be greatly appreciated because I’ve been trying to do this for a while already.

---

<div class="post-metadata">

**Author:** ![alessandro](https://drob5swvtjqxg.cloudfront.net/user_avatar/community.nginx.org/alessandro/32/4836_2.png) [@alessandro](https://community.nginx.org/u/alessandro)\
**Post date:** [June 5, 2025, 12:16pm UTC](https://community.nginx.org/t/trying-to-rate-limit-404-errors-by-ip/4903/2 "2025-06-05T12:16:33Z")

</div>

Heya @j3j5! Can you try removing L30 (`return 404`)? NGINX doesn’t really read code top to bottom, so when it sees a return statement within any given context, that’s usually (in almost all use cases) what it first does. In this case it returns a 404 no matter what. Instead, what you can do is change `limit_req_status 429` to `limit_req_status 404` if you wish to return a 404 error to users that exceed the rate limit 🙂

---

<div class="post-metadata">

**Author:** ![system](https://drob5swvtjqxg.cloudfront.net/user_avatar/community.nginx.org/system/32/19_2.png) [@system](https://community.nginx.org/u/system)\
**Post date:** [July 15, 2025, 9:32pm UTC](https://community.nginx.org/t/trying-to-rate-limit-404-errors-by-ip/4903/3 "2025-07-15T21:32:05Z")

</div>

Closed on July 15, 2025, 9:32pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
