Nginx · The edge of your stack
How should you set Nginx timeouts?
Short answer
Set client header and body timeouts short enough to resist slowloris, keepalive timeouts for real idle reuse, and upstream connect, send and read timeouts based on backend latency. Align them with every proxy in the path.
Timeouts protect worker capacity from slow or dead peers. A timeout that is too short breaks legitimate slow uploads or long-running requests; one that is too long lets bad connections occupy resources.
client_header_timeout 10s;
client_body_timeout 10s;
send_timeout 10s;
keepalive_timeout 65s;
proxy_connect_timeout 3s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;What each timeout covers
- client_header_timeout limits how long a client may take to send headers
- client_body_timeout is the gap between successive body reads
- send_timeout limits the gap between writes to the client
- keepalive_timeout controls how long an idle client connection stays open
- proxy_connect_timeout bounds the TCP handshake to the backend
- proxy_read_timeout is the gap between upstream reads, not the total request duration
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between proxy_connect_timeout and proxy_read_timeout?
- 2How do short timeouts help against slowloris attacks?
- 3Why does a long-running request fail even when data is flowing?
- 4How do you align Nginx timeouts with a cloud load balancer?
Say it in the interview
I keep client header and body timeouts short to protect against slow clients, and set keepalive based on how often real clients reuse connections. For upstreams, connect should be short, while read and send reflect expected backend latency. proxy_read_timeout is between reads, so streaming endpoints need a longer value. I also check every load balancer and CDN in the path, because the shortest timeout wins.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Nginx mock interview and get scored feedback on depth, clarity and confidence.