Disable keep_alive based on specific useragent

Wandenberg Peixoto wandenberg at gmail.com
Tue Nov 18 11:24:41 UTC 2014


Try to remove the last 's'
This should work.

map $http_user_agent $katimeout {
    default 300;
  }

On Tue, Nov 18, 2014 at 2:25 AM, Robert Mueller <robm at fastmail.fm> wrote:

>  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
> <http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout>
> 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
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20141118/97c34d71/attachment.html>


More information about the nginx mailing list