2đź‘Ť
I was getting the “prematurely closed connection” issue because I was trying to communicate to the app through NGINX and uWSGI. The real issue was that the vessel was not being loaded correctly, and by running it manually (outside of the virtualenv) I found out that the issue was a 'site' module not found
error, this was, in turn, caused because the globally installed (using yum, by the way), distributor-provided uWSGI package didn’t have python support built in and the instance couldn’t start correctly. Which takes us to the following…
I think that probably many people has tried to configure uWSGI + NGINX on Linux by following these tutorials:
- http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
- https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-applications-using-uwsgi-web-server-with-nginx
- https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04
And probably some other ones; what they don’t point out is that the uWSGI version you get from the pip
command and from the package distributor are somewhat different, as this uwsgi quickstart guide points out, the distributor may compile uWSGI in a “modular” fashion:
One thing you may want to take into account when testing this
quickstart with distro-supplied packages, is that very probably your
distribution has built uWSGI in modular way (every feature is a
different plugin that must be loaded). To complete this quickstart,
you have to prepend –plugin python,http to the first series of
examples, and –plugin python when the HTTP router is removed…
Whereas the package you get with pip comes with python support right out of the box (at least in my case, on Fedora Linux 23). What is more, since the package manager and pip are independent you can have both the distributor and the pip version simultaneously installed, and if this is already problematic, imagine now a third, local version of the package in your virtualenv. The steps I followed were as follows:
- Remove all and every version of uwsgi you have installed in your system (or at least try to clean up your execution path from either the pip or the distributor-provided package)
- Install only the version of the package you need (or leave only one, in case you didn’t remove everything in the previous step).
-
In case you choose the modular, distributor-provided version:
Make sure you also install the
uwsgi-plugin-python.x86_64
anduwsgi-plugin-python3.x86_64
packages, along with these ones:uwsgi-router-http.x86_64
,uwsgi-plugin-common.x86_64
, and something else you might need. Then, run your uwsgi instance with the--plugin
option to enable either python or python3 support, before any of your other options. The'site' module not found
error should be gone now. You can also use that option in the ini file (likeplugin = python3
) in case you run using config files or vassals. - In case you choose the pip version: Just use it like you would normally do.
In all cases, make sure which version you are calling and you should be fine.