Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Django - SSL with runserver


[sudo] apt-get install stunnel


cd path/to/django/project
mkdir stunnel
cd stunnel

Create the key:

openssl genrsa 1024 > stunnel.key
openssl req -new -x509 -nodes -sha1 -days 365 -key stunnel.key > stunnel.cert
cat stunnel.key stunnel.cert > stunnel.pem

Create the dev_https file with:


cert = stunnel/stunnel.pem
sslVersion = SSLv3
foreground = yes
output = stunnel.log


Now go to project root and create a runserver file:

stunnel4 stunnel/dev_https &
python runserver&

Sets the permission:

chmod a+x runserver

The SSL works in:



This comment has been minimized.

Copy link

@asantoni asantoni commented Dec 25, 2017

Thanks for sharing this. Simple and pretty easy!
I had to comment out the "sslVersion = SSLv3" version line since SSL v3 is super deprecated and Chrome freaks out if you try to use that.


This comment has been minimized.

Copy link

@the94air the94air commented Dec 27, 2017

Thanks @claudiosanches. Looks so nice.


This comment has been minimized.

Copy link

@borninla borninla commented Jul 10, 2018

Thank you @claudiosanches! For future reference, it seems like the stunnel4 command has been deprecated and replaced by stunnel.


This comment has been minimized.

Copy link

@litch0 litch0 commented Jan 10, 2020

This method is no more working for me I get the error:

SyntaxError: invalid syntax", line 16 ) from exc ^ SyntaxError: invalid syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment