Disable keep_alive based on specific useragent

Robert Mueller robm at fastmail.fm
Tue Nov 18 04:25:19 UTC 2014


Hi

Thanks for your responses. Unfortunately, they don't seem to work.

> and then use the evil IF:
>
> if ($ios_ua) { keepalive_timout 0; }

This doesn't appear to work.

if ($http_user_agent ~ "^iOS/8\.") { keepalive_timeout 0; }

nginx: [emerg] "keepalive_timeout" directive is not allowed here
in nginx-http.conf:753 nginx: configuration file nginx-http.conf
test failed

If I do:

# if ($http_user_agent ~ "^iOS/8\.") { keepalive_timeout 0; # }

e.g. comment out the "if" block part, it works fine, but obviously
     disabled keepalive for all requests. So it appears you can't set
     keepalive_timeout in an "if" block.

> I would do even better by avoiding using 'if' at all:
>
> map $http_user_agent $keepalive_timeout { default 75s; # Put here the
> wanted default value (taken from keepalive_timeout[1] docs) *regex* 0;
> *for* 0; *blacklisted* 0; *user agents* 0 }
>
> keepalive_timeout $keepalive_timeout; # At http, server or location
> level, as docs state

This doesn't seem to work either:

map $http_user_agent $katimeout { default 300s; }

keepalive_timeout $katimeout;

nginx: [emerg] "keepalive_timeout" directive invalid value in
nginx-http.conf:53 nginx: configuration file nginx-http.conf test failed

Looks like the value can't be a variable?

Rob



Links:

  1. http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20141118/fee656ce/attachment-0001.html>


More information about the nginx mailing list