Y
Y
Yuri Tatarkin2017-09-25 18:29:34
Nginx
Yuri Tatarkin, 2017-09-25 18:29:34

How to stop downloading a file when closing a page?

How to stop downloading a file when closing a page?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2017-10-05
@HeadOnFire

Nginx has 3 useful directives:

reset_timedout_connection on; # 1
client_body_timeout 5; # 2
send_timeout 2; # 3

What they do:
#1 - If the client stops reading responses from the server, Nginx will drop the connection to it, freeing up resources.
# 2 - Limiting the time to wait for the request body from the client. If the request body does not arrive within this interval, Nginx will drop the connection.
#3 - If the client stops reading the response, Nginx will wait the specified interval and reset the connection.
By default, these values ​​are quite high. If I understand your question correctly, then in fact Nginx does this already (resets the connection with the client that has fallen off), but it does not do it immediately (at the moment the browser tab is closed), but after some time has passed. By reducing these intervals, you can force Nginx to drop connections much earlier. But too low values ​​should not be used - in this case, slow clients will be sent to hell. And half of the mobile clients on half of the mobile networks are slow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question