Nginx – How to configure nginx to serve a “server overloaded” or out of capacity page

503-errorcapacitynginx

I've got a client who's expecting a plug on national TV tonight, and they just told me (love how that works, eh?). I'm trying to do some capacity planning in what little time I have, and the one thing I think I should try would be some form of "out of capacity" page.

The idea is to (a) define a threshold that says, "this is what overloaded means", (b) compare current load with [a] on each request, and if current load >= [a], (c) show a 503 page.

The thing is, I have no idea what this is commonly known as, so Google searches have turned up very little. I know of mod_qos for Apache, but this client is on nginx, and I haven't been able to find an equivalent for nginx.

Any help would be greatly appreciated. Thank you!

Best Answer

There isn't any exact equivalent for Nginx because it's not really needed. Nginx itself will not be your bottleneck, that much is almost guaranteed.

That's not to say you won't have issues, though. Most likely your backend will peak the CPU or you'll run out of bandwidth to serve the files. Nginx is a HTTP reverse proxy, though, it doesn't want to monitor things and I guess this is reflected in the type of modules people write for it.

You basically have two options available to you. If your backend is configured properly to only allow a certain about of processes to run such that you will never run out of memory and that your CPU won't be too busy then you can simply define an error page for the 504 gateway timeout error and tell people that you're over capacity and try to reload in a bit.

If you do load balancing and you prefer nginx itself to limit the requests then you can use one of the 3rd party modules such as EyBalancer or HTTP Health Check, though I can't give any details on how they handle overloading.

Related Topic