Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

486
Views
How to properly set nginx timeouts as proxy?

I am getting a few 502 errors in nginx:

2020/05/05 20:40:05 [error] 13425#0: *1360447 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.31.12.13, server: , request: "POST /app/functionHTTP/1.1", upstream: "http://127.0.0.1:8080/app/function", host: "example.com"

Architecture:

client - load balancer - instances (each with nginx proxy for NodeJS http server)

Timeout values:

  • client:

    • request timeout: 60s
  • load balancer:

    • keepalive timeout: 60s
  • nginx:

    • http keepalive_timeout: 65s
    • upstream keepalive_timeout: 60s
    • upstream keepalive: 256 connections
    • proxy_connect_timeout: 60s
    • proxy_read_timeout: 60s
    • proxy_send_timeout: 60s
  • server (NodeJS):

    • request timeout: 50s
    • keepAliveTimeout: 65s
    • headersTimeout: 70s

The 502 errors occur rarely (~0.01% of requests) but consistently.

What I've checked so far:

  • Limit of file descriptors not reached
  • Limit of nginx connections not reached
  • Limit of TCP ports not reached
  • Limit of CPU, memory, disk I/O not reached

It looks much like a race condition where the NodeJS server closed the connection and nginx is assuming the connection still exists.

What would be proper nginx timeout values in the current setting?

(I am unsure whether this isn't rather a question for ServerFault?)

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!