I have Apache httpd (2.2.22) configured as reverse proxy.
There is a situation in which I need to take my web server (the receiver of the proxied requests) offline for a few milliseconds. During this time the web server should not receive any requests but I also don't want to reject any requests.
What I'd like to do is to somehow get httpd to delay all requests for that period of time. In steps:
- tell httpd to delay all requests until further notice
- stop web server
- start web server
- continue request forwarding from httpd
A fixed delay would also do the trick but since I cannot foresee the actual amount of time the web server will be offline (other than that it will be less than one second), a dynamical approach would be better suited.
I've looked at how mod_proxy or mod_balancer could help me but I didn't find an obvious solution.
I'll be happy about any pointers you can give me.
Edit:
It looks like a static approach is sufficient.
Some helpful resources:
- httpd ProxyPass
- httpd ProxyTimeout
- ProxyPass with mod_rewrite (no need to use ProxyPass explicitly; no need to use ProxyPassInterpolateEnv)
- See also this post for a discussion on httpd returning 503 immediately (proxy and balancer).
Alternative solution:
We will be deploying systemd to our servers. systemd will solve my problem because it can retain requests on sockets that are closed on one end. This means that when I stop the backend server for a short period of time, all the requests will be queued until I start it again and connect to the socket. That's what I call elegant 🙂
Best Answer
The
ProxyPass
directive accepts many parameters to configure how the connection is handled with the backend server.Among those parameters, you may be interested by:
connectiontimeout <n>
: The number of seconds Apache waits for the creation of a connection to the backend to complete.timeout <n>
: The number of seconds Apache waits for data sent by/to the backend.ttl <n>
: Time to live for inactive connections and associated connection pool entries, in seconds.A better solution would be to have multiple backend servers and balance the load over the members and detect offline servers using the
ping
parameter. So, when you reboot a backend server, another one could take the relay.