Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Nginx connection timeout for specific request pattern

In application I want to increase connection timeout as there is functionality to upload huge files. Currently I found the next properties:

 proxy_connect_timeout     20;
 proxy_send_timeout        20;
 proxy_read_timeout        20;

But the thing is that I looking to not allow so long connection through all endpoint but only for particular one.

Is there some way to configure Nginx "connection timeout" for particular request pattern?

like image 685
Speise Avatar asked Jul 09 '26 03:07

Speise


1 Answers

Yes! One of the nice things about nginx is that you can set values in a hierarchy depending on locations, paths, parameters, source IP addresses ... basically on any metadata.

server {
    listen 443 ssl http2;
    ....
    # default timeouts here
    proxy_connect_timeout <smallval>;
    proxy_send_timeout <smallval>;
    proxy_read_timeout <smallval>;

    location /biguploadshere {
        proxy_connect_timeout <bigval>;
        proxy_send_timeout <bigval>;
        proxy_read_timeout <bigval>;
    }
}
like image 62
PaulProgrammer Avatar answered Jul 11 '26 18:07

PaulProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!