Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Keep-Alive per Directory

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

like image 231
NNN Avatar asked Jun 01 '10 18:06

NNN


People also ask

What is the default Keep-Alive timeout in Apache?

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.

How do I enable Keep-Alive?

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.


2 Answers

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.

like image 117
acdcjunior Avatar answered Oct 19 '22 04:10

acdcjunior


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

like image 42
Liron Cohen Avatar answered Oct 19 '22 05:10

Liron Cohen