0
0
Nginxdevops~20 mins

Keepalive connections in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Keepalive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the purpose of keepalive connections in nginx?

Choose the best explanation for why nginx uses keepalive connections.

ATo close connections immediately after each request to save memory.
BTo encrypt all connections automatically without extra configuration.
CTo reuse TCP connections for multiple requests, reducing latency and CPU usage.
DTo limit the number of simultaneous connections to a fixed number.
Attempts:
2 left
💡 Hint

Think about how reusing connections affects speed and resource use.

Configuration
intermediate
1:30remaining
Identify the correct nginx directive to enable keepalive connections to an upstream server

Which configuration snippet correctly enables keepalive connections for upstream servers in nginx?

Nginx
upstream backend {
    server backend1.example.com;
    server backend2.example.com;
    # Which line enables keepalive?
}
Akeepalive 32;
Bkeepalive_timeout 32;
Ckeepalive_disable off;
Dkeepalive_requests 32;
Attempts:
2 left
💡 Hint

Look for the directive that sets the number of idle keepalive connections.

💻 Command Output
advanced
1:30remaining
What is the output of this nginx status command regarding keepalive connections?

Given the following snippet from nginx_status output, what does the Keep-Alive field represent?

Nginx
Active connections: 291 
server accepts handled requests
 166309 166309 310704 
Reading: 12 Writing: 14 Waiting: 265
Keep-Alive: 150
AThe total number of keepalive connections closed since server start.
BThe number of currently open keepalive connections waiting for requests.
CThe maximum allowed keepalive connections configured in nginx.
DThe number of keepalive connections rejected due to timeout.
Attempts:
2 left
💡 Hint

Focus on what 'Waiting' and 'Keep-Alive' mean in nginx status.

Troubleshoot
advanced
1:30remaining
Why might nginx close keepalive connections prematurely?

After enabling keepalive connections, nginx closes them too soon. Which configuration is most likely causing this?

Akeepalive_timeout 5s;
Bkeepalive 100;
Cclient_max_body_size 1m;
Dproxy_buffering off;
Attempts:
2 left
💡 Hint

Consider which setting controls how long idle connections stay open.

🔀 Workflow
expert
2:30remaining
Order the steps to enable and verify keepalive connections in nginx

Put these steps in the correct order to enable and confirm keepalive connections work in nginx.

A1,2,4,3
B4,1,2,3
C2,1,4,3
D1,4,2,3
Attempts:
2 left
💡 Hint

Think about configuration first, then client setup, then reload, then verification.