# Nginx 404 showing when I configured for a custom 404 page

**URL:** <https://www.ruby-forum.com/t/nginx-404-showing-when-i-configured-for-a-custom-404-page/219843>\
**Category:** NGINX\
**Created:** [May 18, 2012, 1:35am UTC](https://www.ruby-forum.com/t/nginx-404-showing-when-i-configured-for-a-custom-404-page/219843 "2012-05-18T01:35:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 18, 2012, 1:35am UTC](https://www.ruby-forum.com/t/nginx-404-showing-when-i-configured-for-a-custom-404-page/219843/1 "2012-05-18T01:35:05Z")

</div>

Hi all,

I have a 404 custom page set like this

```
    error_page 404 = @errorpages;

    error_page 500 = @errorpages;

    location @errorpages {

                root /var/www/;

                internal;

                proxy_pass http://localhost:82;

                proxy_set_header Host $host;

                proxy_set_header X-Real-IP $remote_addr;

                proxy_set_header Accept-Encoding "";

                proxy_ignore_headers Set-Cookie;

                proxy_ignore_headers Cache-Control;

                proxy_ignore_headers Expires;

                proxy_ignore_headers X-Accel-Expires;

                add_header X-Cache-Status $upstream_cache_status;

                proxy_cache cache;

                proxy_cache_key $request_uri;

        proxy_cache_use_stale updating;

    }

```

But every now and then I am hitting the nginx vanilla 404 pages,  
especially  
when hitting rate limiting.

How do I close the gaps to ensure I am showing only the custom 404’s ?

- Quintin

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [May 18, 2012, 11:49am UTC](https://www.ruby-forum.com/t/nginx-404-showing-when-i-configured-for-a-custom-404-page/219843/2 "2012-05-18T11:49:15Z")

</div>

Hello!

On Thu, May 17, 2012 at 04:34:14PM -0700, Quintin P. wrote:

> ```
> proxy_pass http://localhost:82;
> 
> ```

[…]

> ```
> }
> 
> ```
> 
> But every now and then I am hitting the nginx vanilla 404 pages, especially  
> when hitting rate limiting.
> 
> How do I close the gaps to ensure I am showing only the custom 404’s ?

Most likely you are see double errors with 404 being the last  
one. By default nginx returns builtin error page in such cases,  
unless recursive\_error\_pages is set. (And it’s not really good  
idea to change the default unless you understand what are you  
doing and sure it won’t create loops.)

I would recommend to

a) use static files for error pages;

b) make sure no limits are applied to error pages location.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [June 23, 2012, 6:11pm UTC](https://www.ruby-forum.com/t/nginx-404-showing-when-i-configured-for-a-custom-404-page/219843/3 "2012-06-23T18:11:02Z")

</div>

Bumping up and old thread.

How can I ensure I don’t set rate limiting for my 404 pages with the  
scenario that maxim explained?

My rate limiting is set to the whole site at /

- Quintin

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [June 1, 2012, 1:18am UTC](https://www.ruby-forum.com/t/nginx-404-showing-when-i-configured-for-a-custom-404-page/219843/4 "2012-06-01T01:18:05Z")

</div>

Thanks Maxim.

Is there a way I can debug this?

This is for 404 and since there are no errors for 404’s from my hunch  
this  
should be working. I use static for 500’s

Also how do I exclude error pages form limits? Is there a standard  
pattern? I do rate limiting like this

limit\_req\_zone $binary\_remote\_addr zone=pw:30m rate=20r/m;

```
    location / {

                if (-f /var/www/statichtmls/build.html) {

            return 503;

        }

                limit_req zone=pw burst=5 nodelay;

```

for the whole site.

- Quintin
