Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx keepalive timeout vs ELB idle timeout vs proxy_read_timeout

Tags:

nginx

aws-elb

My request flow looks like Client -> AWS ELB -> Nginx -> Backend.

The backend takes a long time to respond to some requests, so proxy_read_timeout is set to 5 min. However, nginx default keepAliveTimeout is 70 sec and AWS ELB idleTimeout is 6 min.

The AWS documentation says to keep the AWS idleTimeout less than the backend's keeplalive timeout which is 70 sec in my case. Where does nginx default keepAliveTimeout come into the picture here?

like image 933
Haneef Ali Avatar asked Oct 16 '25 11:10

Haneef Ali


1 Answers

In this particular scenario, nginx is the backend for ELB. So, nginx's keepalive_timeout for the downstream connections should be greater than 6 minutes. However, make sure you set the keepalive_timeout in the right nginx config context since there are actually two different configs named keepalive_timeout.

In nginx:

  • keepalive_timeout set in the http, server, or location context means the timeout for the downstream connections. In your case, it's nginx-to-ELB connections.

  • keepalive_timeout set in the upstream context means the timeout during which an idle keepalive connection to an upstream (i.e., your actual backend) server will stay open. This knob is called idleTimeout in ELB terminology.

Notice that the same recommendation of having the idleTimeout greater than the backend's keepalive timeout applies to your nginx itself. See the graphical explanation or read my article on how the misconfigured timeouts can lead to unexpected HTTP 502s for more details:

enter image description here

like image 64
Ivan Velichko Avatar answered Oct 18 '25 11:10

Ivan Velichko



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!