14

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

fnkr
  • 9,428
  • 6
  • 54
  • 61

2 Answers2

22

I just found the solution:

location /ip/ {
    keepalive_timeout 0;
}
fnkr
  • 9,428
  • 6
  • 54
  • 61
1

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.

AntonioK
  • 440
  • 6
  • 20
Déjà vu
  • 28,223
  • 6
  • 72
  • 100
  • It looks like its not possible to change the user agent with an `XMLHTTPRequest`. http://stackoverflow.com/a/5862744/1485952 – fnkr Jun 09 '13 at 14:20
  • 3
    This is not a neat solution because you cannot use arbitrary user-agent strings for this trick. – rjha94 Aug 28 '14 at 17:23