1

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?

Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90
Haneef Ali
  • 15
  • 5

1 Answers1

5

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

Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90