keepalive_disable
The `keepalive_disable` directive disables HTTP keep-alive for specified user agents.
Description
The keepalive_disable directive is used in NGINX to control the behavior of HTTP keep-alive connections based on the user agent string of the client making the request. When specified, this directive allows you to list one or more user agents that will be denied the benefit of persistent connections. Disabling keep-alive can result in increased latency as each request will require a new TCP connection to be established and torn down, rather than reusing the existing connection.
The directive accepts one or more arguments, which should be strings that specify user agent substrings. If a client's user agent matches any of the specified substrings, the client will not utilize keep-alive connections. This can be useful for dealing with problematic clients that have known issues with persistent connections, such as older browsers or specific bots. The directive can be used in the http, server, or location contexts, giving it flexibility in where it can be applied based on the desired use case.
When this directive is defined without any parameters, it effectively does nothing and keeps the default behavior of allowing keep-alive. Conversely, if one or more strings are provided, it creates a rule that evaluates incoming requests against the specified user agents to determine if keep-alive should be disabled. This directive is useful for tuning server performance and resource management, particularly in scenarios where certain clients may cause performance issues or where resources are scarce.
Config Example
http {
keepalive_disable "MSIE";
keepalive_disable "Opera";
}
server {
location / {
keepalive_disable "FacebookExternalHit";
}
}Careful about the exact user agent strings; partial matches can lead to unexpected results.
Adding too many user agents may degrade performance for those clients if keep-alive is ignored.