Home Blog uWSGI and Django Secure Requests

uWSGI and Django Secure Requests

Posted in Django on October 29, 2010 (view comments)
uWSGI and Django Secure Requests

A colleague and I ran into a frustrating situation this evening when transitioning a site from Apache and mod_wsgi to uWSGI. Django's request.is_secure() wasn't working correctly. After much Googling and shouting at the SSH console, we finally discovered the UWSGI_SCHEME uWSGI parameter.

To fix the issue, we edited /etc/nginx/uwsgi_params (which originally comes from nginx/uwsgi_params in the uWSGI tarball) and added an additional param at the bottom:

uwsgi_param  UWSGI_SCHEME   $scheme;

This prompts uWSGI to set wsgi.url_scheme to the appropriate value, which Django then detects in the wsgi handler.

I'd really love to see this in the documentation on the uWSGI site, or (even better) included by default in the uwsgi_params in the tarball. In the meantime, though, it's a relatively quick and easy fix. Enjoy!

Comments

blog comments powered by Disqus

Brandon Konkle

I've been creating websites for over 10 years, and I've been using Django since early 2008. I focus on high quality, well-tested, maintainable code and reliable high-performance deployments. Web development is something that I am very excited about, and I love finding elegant and innovative ways to push web applications further.

Latest Comments

© 2011 Copyright Brandon Konkle. All Rights Reserved.