Configure Nginx connection timeout for specific request pattern

9/26/2019

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?

-- Speise
kubernetes
kubernetes-ingress
nginx

1 Answer

9/26/2019

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>;
    }
}
-- PaulProgrammer
Source: StackOverflow