Force nginx to close connection instantly

2019-04-22 08:35发布

问题:

How do I let nginx close the tcp connection instantly after the request is fulfilled?

回答1:

I just found the solution:

location /ip/ {
    keepalive_timeout 0;
}


回答2:

The connection is maintained between the server and the browser thanks to the Keep Alive requests exchanged between them.

You can disable the Keep Alive behavior for a particular user agent: see the nginx manual

keepalive_disable ua

You can probably trick your browser to have a given user agent, having the keep alive cut only for your particular needs.