Is it possible to disable Keep-Alive on a directory basis?
For example, I have an API that runs on something like domain.com/api/
It'd be nice if KeepAlive was not used on any requests in the /api/ directory.
Update/Solution:
SetEnvIf Request_URI /api/ nokeepalive
Source: http://httpd.apache.org/docs/2.2/env.html
However, the default setting for Apache Keepalive Timeout is 15 seconds. In computer terms, this is an eternity. If it takes 2 seconds to load a webpage, then, the slot is active for 2 seconds, serving requests, and then waits 15 seconds longer, waiting to see if the user needs anything else.
To enable Keep-Alive, you need to explicitly request it via the HTTP header by accessing . htaccess or the main configuration file of your web server. If you turn on Keep-Alive, the HTTP response header will show Connection: keep-alive.
This seems to be a recent feature of Apache HTTPD, but it works.
To disable (turn off) Keep-Alive for a specific directory, use:
SetEnvIf Request_URI /myDir/ nokeepalive
Add this to your httpd.conf
or .htaccess
file!
Source: Environment Variables in Apache - Special Purpose Environment Variables - nokeepalive.
There are 2 ways I found:
1. As described by acdcjunior you can do it with SetEnvIf inside your Virtual host or main configuration
SetEnvIf Request_URI /myDir/ nokeepalive
2. You can just set the Connection header to close
Header set Connection "close"
I prefer the second option due to the fact that this will allow the entire configuration to be under the
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With