Welcome! Log In Create A New Profile


Disable Keepalive based on User-Agent

Posted by metula 
Disable Keepalive based on User-Agent
November 26, 2009 05:41AM
nginx v0.7.64 on CentOS 5.3

We would like to be able to disable keepalive based on the User-Agent - specifically, we'd like to disable for MSIE 4.x,5.x,6.x

Even though the docs suggest it should work, the following config extract is rejected. We've tried various ways of setting the keepalive value - doesn't matter if we try keepalive_timeout or keepalive_requests - it won't let us change the value. Unfortunately we also can't do

keepalive_timeout $someVariable

here's the extract


server {
listen 85;
server_name www.testingblah.com;

ancient_browser msie 4;
ancient_browser msie 5;
ancient_browser msie 6;

set $kvalue keepaliveon;
if ($ancient_browser){
set $kvalue keepaliveoff;

if ($kvalue = keepaliveon) {
keepalive_requests 50; //line 52
if ($kvalue = keepaliveoff) {
keepalive_requests 0;

location / {
proxy_pass http://WebHTTP;


Error Message on startup is:

[emerg]: "keepalive_requests" directive is not allowed here in /data/apps/nginx/conf/nginx.conf:52

Any help - including alternative methods of achieving this requirement would be greatly appreciated.. we're looking for alternatives to lighttpd which is too buggy for us.
Re: Disable Keepalive based on User-Agent
November 26, 2009 06:00AM
Update: using keepalive_requests is not going to work anyway as this would clearly be a per-socket one-time configuration - however, there should be a way of disabling keepalive for a specific request (based on User-Agent or any other factor) - setting the keepalive_timeout to 0 would seem reasonable?
Re: Disable Keepalive based on User-Agent
November 26, 2009 07:07AM
Update: In apache we can also do this by downgrading a connection to HTTP/1.0 and/or setting nokeepalive=true
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 93
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready