Leandro Abilio
Leandro Abilio

Reputation: 57

SSL Using Gunicorn for Django

I'm running a django project using gunicorn, I'd like to run it using ssl, I found on internet that I need this dictionary "{'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-SSL': 'on'}". But where do i put it? Is there a way to run it using ssl on command gunicorn_django? Im not using nginx and I wouldn't like to use. Thanks.

Upvotes: 1

Views: 2790

Answers (1)

Mark Lavin
Mark Lavin

Reputation: 25164

Update: Gunicorn added SSL support as of 0.17.0 / 2012-12-25.

Original answer:

Gunicorn itself does not support SSL. There is an open pull request to add it https://github.com/benoitc/gunicorn/pull/265. The X-FORWARDED-PROTOCOL and X-FORWARDED-SSL headers would be used by a proxy (such as Nginx) in front of Gunicorn which does SSL termination.

Using Nginx is not required to use SSL. You could use Apache/mod_proxy or HAProxy or any other proxy server which supports SSL. Even without the need for SSL the use of a proxy server is recommended when using Gunicorn to buffer slow clients http://gunicorn.org/deploy.html

Although there are many HTTP proxies available, we strongly advise that you use Nginx. If you choose another proxy server you need to make sure that it buffers slow clients when you use default Gunicorn workers. Without this buffering Gunicorn will be easily susceptible to denial-of-service attacks. You can use slowloris to check if your proxy is behaving properly.

Upvotes: 5

Related Questions