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!

Tomek
  • 116
  • 2
  • 11

1 Answers1

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

Batiaev
  • 1,173
  • 1
  • 14
  • 30
  • This solution might work but is not workable in high traffic websites if developer has written over time consuming apps. – Amit Jaiswal Apr 26 '16 at 07: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 Apr 26 '16 at 08:51
  • 1
    Tried this but didn't help :( – Ashit Vora Aug 31 '17 at 03:31