Bird
Raised Fist0
Nginxdevops~10 mins

Proxy timeouts in Nginx - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Proxy timeouts
Client sends request
↓
Nginx receives request
↓
Nginx forwards request to backend
↓
Wait for backend response
↓
Timeout reached?
Yes→Return error to client
↓
Timeout reached?
No→Receive backend response
↓
Send response to client
Nginx receives a client request, forwards it to the backend server, waits for a response until a timeout occurs, then either returns the backend response or an error if timeout is reached.
Execution Sample
Nginx
proxy_connect_timeout 5s;
proxy_read_timeout 10s;
proxy_send_timeout 5s;
This config sets time limits for connecting, reading, and sending data to the backend server.
Process Table
StepActionTimeout TypeTimeout ValueResult
1Client sends requestN/AN/ARequest received by Nginx
2Nginx tries to connect to backendproxy_connect_timeout5sConnection established within 5s
3Nginx sends request data to backendproxy_send_timeout5sData sent successfully within 5s
4Nginx waits for backend responseproxy_read_timeout10sResponse received within 10s
5Nginx sends response to clientN/AN/AResponse delivered successfully
6If connection not established in 5sproxy_connect_timeout5sTimeout error returned to client
7If sending data exceeds 5sproxy_send_timeout5sTimeout error returned to client
8If backend response not received in 10sproxy_read_timeout10sTimeout error returned to client
💡 Execution stops when response is sent to client or timeout error occurs.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Connection StatusNot connectedConnectedConnectedConnectedConnected or Timeout Error
Data Sent StatusNot sentNot sentSentSentSent or Timeout Error
Response StatusNo responseNo responseNo responseReceivedReceived or Timeout Error
Key Moments - 3 Insights
Why does Nginx return a timeout error even if the backend server is up?
Because the timeout can occur at different stages: connection, sending data, or waiting for response. If any stage exceeds its timeout (see steps 6-8 in execution_table), Nginx returns an error.
What happens if the backend responds just before the proxy_read_timeout expires?
Nginx accepts the response and forwards it to the client successfully (see step 4 and 5 in execution_table). The timeout only triggers if the wait exceeds the configured time.
Can proxy_send_timeout cause a timeout if the backend is slow to receive data?
Yes, if sending data to the backend takes longer than proxy_send_timeout (step 7), Nginx returns a timeout error.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does Nginx check if the backend response timeout is reached?
AStep 4
BStep 2
CStep 6
DStep 3
💡 Hint
Check the 'Timeout Type' column for 'proxy_read_timeout' in execution_table step 4.
According to variable_tracker, what is the 'Connection Status' after step 2?
ANot connected
BConnected
CTimeout Error
DNo response
💡 Hint
Look at the 'Connection Status' row and the 'After Step 2' column in variable_tracker.
If proxy_send_timeout is set to 3s instead of 5s, which step in execution_table would most likely change?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
proxy_send_timeout relates to sending data to backend, shown in step 3 of execution_table.
Concept Snapshot
Nginx proxy timeouts control how long Nginx waits at each stage:
- proxy_connect_timeout: max time to connect to backend
- proxy_send_timeout: max time to send request data
- proxy_read_timeout: max time to wait for backend response
If any timeout is exceeded, Nginx returns an error to client.
Full Transcript
This visual execution shows how Nginx handles proxy timeouts. When a client sends a request, Nginx tries to connect to the backend within proxy_connect_timeout. Then it sends data within proxy_send_timeout. Next, it waits for the backend response within proxy_read_timeout. If any of these steps take longer than their timeout, Nginx returns a timeout error to the client. Otherwise, it forwards the backend response. Variables like connection status, data sent status, and response status change step-by-step as shown. Key moments clarify common confusions about when timeouts happen and their effects.

Practice

(1/5)
1. What does the proxy_connect_timeout directive control in Nginx?
easy
A. The time Nginx waits to receive the full response from the backend
B. The time Nginx waits to send the full request to the backend
C. The time Nginx waits to establish a connection with the backend server
D. The time Nginx caches the response from the backend

Solution

  1. Step 1: Understand proxy_connect_timeout purpose

    This directive sets how long Nginx waits to connect to the backend server before giving up.
  2. Step 2: Differentiate from other timeouts

    proxy_send_timeout controls sending request time, proxy_read_timeout controls response wait time, so they are different.
  3. Final Answer:

    The time Nginx waits to establish a connection with the backend server -> Option C
  4. Quick Check:

    proxy_connect_timeout = connection wait time [OK]
Hint: Connect timeout is for establishing backend connection only [OK]
Common Mistakes:
  • Confusing connect timeout with read or send timeout
  • Thinking it controls response wait time
  • Assuming it caches responses
2. Which of the following is the correct syntax to set a 10-second proxy read timeout in Nginx?
easy
A. proxy_read_timeout 10;
B. proxy_read_timeout 10s;
C. proxy_read_timeout = 10s;
D. proxy_read_timeout: 10s;

Solution

  1. Step 1: Recall Nginx timeout syntax

    Timeout values are set as numbers with optional time units, but seconds are default so '10' means 10 seconds.
  2. Step 2: Check syntax correctness

    Correct syntax is proxy_read_timeout 10; without '=' or ':' and without 's' suffix.
  3. Final Answer:

    proxy_read_timeout 10; -> Option A
  4. Quick Check:

    Timeouts use number only, no '=' or ':' [OK]
Hint: Use number only for seconds, no '=' or ':' in directives [OK]
Common Mistakes:
  • Adding '=' sign which is invalid
  • Using ':' instead of space
  • Adding 's' suffix which is not required
3. Given this Nginx config snippet:
location /api/ {
  proxy_pass http://backend;
  proxy_connect_timeout 5;
  proxy_send_timeout 10;
  proxy_read_timeout 15;
}

What happens if the backend server takes 20 seconds to send the full response?
medium
A. Nginx closes connection after 10 seconds waiting to send request
B. Nginx closes connection after 5 seconds trying to connect
C. Nginx waits indefinitely for the backend response
D. Nginx closes connection after 15 seconds waiting for response

Solution

  1. Step 1: Identify relevant timeout for response wait

    proxy_read_timeout controls how long Nginx waits for the backend to send the full response.
  2. Step 2: Compare backend response time with proxy_read_timeout

    Backend takes 20 seconds, proxy_read_timeout is 15 seconds, so Nginx closes the connection after 15 seconds.
  3. Final Answer:

    Nginx closes connection after 15 seconds waiting for response -> Option D
  4. Quick Check:

    Response wait = proxy_read_timeout = 15 [OK]
Hint: Response wait time controlled by proxy_read_timeout [OK]
Common Mistakes:
  • Confusing send timeout with read timeout
  • Assuming connect timeout applies to response wait
  • Thinking Nginx waits forever
4. You set proxy_connect_timeout 10; but Nginx still times out connecting to backend after 5 seconds. What is the likely cause?
medium
A. The backend server is closing connections early
B. There is a lower timeout set by proxy_connect_timeout in a lower-level block
C. Nginx ignores proxy_connect_timeout and uses default 5 seconds
D. The proxy_connect_timeout directive is misspelled

Solution

  1. Step 1: Understand directive inheritance in Nginx

    Timeout directives can be set at multiple levels; lower-level settings override higher-level ones.
  2. Step 2: Identify cause of shorter timeout

    If a lower-level block has a 5-second timeout, it overrides the 10-second setting.
  3. Final Answer:

    There is a lower timeout set by proxy_connect_timeout in a lower-level block -> Option B
  4. Quick Check:

    Timeouts can be overridden by lower-level config [OK]
Hint: Check for overriding timeouts in child blocks [OK]
Common Mistakes:
  • Assuming Nginx ignores the directive
  • Blaming backend without checking config
  • Misspelling directive (would cause error, not timeout)
5. You want Nginx to wait up to 20 seconds to connect to backend, 30 seconds to send the request, and 40 seconds to receive the response. Which configuration snippet correctly sets these timeouts?
hard
A. proxy_connect_timeout 20; proxy_send_timeout 30; proxy_read_timeout 40;
B. proxy_connect_timeout 20s; proxy_send_timeout 30s; proxy_read_timeout 40s;
C. proxy_connect_timeout=20; proxy_send_timeout=30; proxy_read_timeout=40;
D. proxy_connect_timeout: 20; proxy_send_timeout: 30; proxy_read_timeout: 40;

Solution

  1. Step 1: Recall correct syntax for timeout directives

    Timeouts are set as directive name followed by a space and number (seconds), ending with semicolon; no '=' or ':' or 's' suffix needed.
  2. Step 2: Validate each option

    proxy_connect_timeout 20; proxy_send_timeout 30; proxy_read_timeout 40; uses correct syntax; A uses ':'; B adds unnecessary 's'; C uses '='.
  3. Final Answer:

    proxy_connect_timeout 20; proxy_send_timeout 30; proxy_read_timeout 40; -> Option A
  4. Quick Check:

    Use number only with semicolon, no '=' or ':' [OK]
Hint: Timeouts use number only, no '=' or ':' [OK]
Common Mistakes:
  • Adding 's' suffix to numbers
  • Using '=' or ':' instead of space
  • Missing semicolon at line end
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard