Given the following nginx upstream configuration, what is the maximum number of idle keepalive connections nginx will maintain to the upstream servers?
upstream backend {
server backend1.example.com max_fails=3 fail_timeout=30s;
server backend2.example.com max_fails=3 fail_timeout=30s;
keepalive 10;
}
server {
location / {
proxy_pass http://backend;
}
}Think about what the keepalive directive controls in the upstream block.
The keepalive 10; directive sets the maximum number of idle keepalive connections per upstream server (not total across all). So nginx will keep up to 10 connections open per server (20 total with two servers).
Which of the following nginx upstream configurations correctly enables connection pooling with 20 keepalive connections per upstream server?
Remember the exact syntax for the keepalive directive inside the upstream block.
The keepalive directive is set once inside the upstream block to specify the maximum number of idle keepalive connections per server. It is not set per server and does not use an equals sign.
An nginx server is configured with an upstream block using keepalive 15;. However, monitoring shows nginx opens many more than 15 connections to the upstream servers under load. What is the most likely cause?
Consider the difference between idle and active connections in nginx's connection pooling.
The keepalive directive limits the number of idle keepalive connections nginx keeps open to upstream servers. When requests come in, nginx can open additional active connections beyond this limit. So under load, total connections can exceed the keepalive number.
You want to configure nginx to reuse TCP connections to upstream servers to improve performance. Which sequence of steps is correct?
Think about the order of defining upstream, enabling keepalive, and configuring proxy headers.
First define the upstream servers, then enable keepalive connections in that block. Next, set proxy_http_version to 1.1 to support keepalive, and finally set the Connection header properly to reuse connections.
When configuring connection pooling with multiple upstream servers in nginx, which practice helps ensure efficient connection reuse and load balancing?
Consider how nginx manages pooled connections and load balancing across servers.
Using a single upstream block with multiple servers and a keepalive directive allows nginx to maintain pools of idle connections to each server that can be reused efficiently across all servers, improving performance and load distribution.