Setting Keepalive_timeout for specific location.

Maxim Dounin mdounin at mdounin.ru
Thu Jul 18 10:14:16 UTC 2013


Hello!

On Thu, Jul 18, 2013 at 05:06:26PM +0800, Kim Yong wrote:

> Hi I'd like to know if setting keepalive for a specific location is
> possible. Right now I have only managed to get it working on server {}
> directive but not location {} directive.

Yes, it's possible, and works fine on all versions I know.  Test 
config:

    location / {
        keepalive_timeout 5;
        return 204;
    }
    location /short {
        keepalive_timeout 1;
        return 204;
    }

Simple test which shows it actually works as expected:

$ time telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1
Host: x

HTTP/1.1 204 No Content
Server: nginx/1.5.3
Date: Thu, 18 Jul 2013 10:11:18 GMT
Connection: keep-alive

Connection closed by foreign host.
        5.45 real         0.00 user         0.00 sys

$ time telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /short HTTP/1.1
Host: x

HTTP/1.1 204 No Content
Server: nginx/1.5.3
Date: Thu, 18 Jul 2013 10:12:10 GMT
Connection: keep-alive

Connection closed by foreign host.
        1.50 real         0.00 user         0.00 sys


If it doesn't work for you - you probably did something wrong.

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx mailing list