I'd like to have Nginx suspend (hold) http requests for short periods of time, while I upgrade or restart the backend service, do a database migration, or some other administrative task, without causing errors to the end users.
Basically I'd like to do the following sequence of operations:
- tell Nginx to stop forwarding requests to my backend, instead holding them in its asynchronous queues;
- wait for and be notified when all pending requests to the backend are completed;
- upgrade, restart, or otherwise operate on the idle backend service;
- quickly verify that the backend service is operational, using its private address;
- open Nginx's flood gates and let all the pending requests through.
Ideally, this would let me perform administrative tasks that need exclusive access to the entire backend server, such as restarts, upgrades, or migrations, without causing end users anything more serious than a delay, hopefully of less than a minute.
I have found this solution, but it's not addressing point 2. Moreover, it needs the Lua interpreter compiled into Nginx, with any memory leaks and security issues that might imply.
Is there any configuration trick or Nginx module specifically targeting this issue? Can it be done with stock Nginx, maybe by testing for the existence of a control file?
How are other admins addressing this issue at large?
(I know that the all-purpose and somewhat sprawling uWSGI application server has this feature, among hundreds of others, but I'd rather avoid introducing yet another element between Nginx and my backend.)