Nginx - sometimes throws 502 Bad Gateway

2019-07-24 08:31发布

问题:

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:

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