Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Last active February 20, 2024 09:59
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save claudiosanches/7012524 to your computer and use it in GitHub Desktop.
Save claudiosanches/7012524 to your computer and use it in GitHub Desktop.
Django - SSL with runserver

Instalation

[sudo] apt-get install stunnel

Configuration

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:

pid=

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

[https]
accept=8443
connect=8001
TIMEOUTclose=1

Now go to project root and create a runserver file:

stunnel4 stunnel/dev_https &
python manage.py runserver&

Sets the permission:

chmod a+x runserver

The SSL works in:

https://localhost:8443 
REF

http://stackoverflow.com/questions/8023126/how-can-i-test-https-connections-with-django-as-easily-as-i-can-non-https-connec

@asantoni
Copy link

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.

@the94air
Copy link

Thanks @claudiosanches. Looks so nice.

@andrewlvovsky
Copy link

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

@lmtr0
Copy link

lmtr0 commented Jan 10, 2020

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

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

@dales
Copy link

dales commented May 1, 2022

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

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

Perhaps you are missing python3 (and you are typing python)

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