Nginx 404 showing when I configured for a custom 404 page

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

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.

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

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