Thursday, December 4, 2014

nginx + uwsgi + web2py: 502 Bad Gateway Error

I started receiving this on one of 2 load balanced servers. Nginx's logs showed this:
upstream prematurely closed connection while reading response header from upstream
I tried restarting uwsgi:
restart uwsgi-emperor
Uwsgi restarted fine, but the problem still persisted. Uwsgi's log showed this:
Fatal Python error: Couldn't create autoTLSkey mapping
This was fixed by doubling the memory in the uwsgi config file (/etc/uwsgi/web2py.ini) from:
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
limit-as = 1024
reload-on-as = 512
reload-on-rss = 384
and restarting uwsgi.


  1. This helped me tremendously for a similar problem. I was calling pandas from web2py and nginx complained similarly till I doubled the memory as you suggest. Thx a lot!