1

I've got a project Django, gunicorn, nginx.

It mostly works (most of the endpoints), but sometimes nginx throws 502 BAD GATEWAY.

Error is upstream prematurely closed connection while reading response header from upstream Do you have any idea what's wrong with it?

Thanks!

1 Answer 1

3

Sometimes it's happen when page render time more longer then expected

Try to increase timeout (nginx has 60s default timeout)

proxy_send_timeout 180s;
proxy_read_timeout 180s;

Read more here http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout

3
  • This solution might work but is not workable in high traffic websites if developer has written over time consuming apps. Commented Apr 26, 2016 at 7:54
  • Agreed, but anyway I think will better try to increase timeout and investigate backend speed issues, or start thinking about load balancing with couple backend servers if you have high traffic website, nginx is pretty good in this area
    – Batiaev
    Commented Apr 26, 2016 at 8:51
  • 1
    Tried this but didn't help :(
    – Ashit Vora
    Commented Aug 31, 2017 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.