Skip to content

Instantly share code, notes, and snippets.

@cfchou
Forked from claudiosanches/django-runserver-ssl.md
Last active August 30, 2018 03:34
Show Gist options
  • Save cfchou/08065983e4c739165d8abcfe8420cb3e to your computer and use it in GitHub Desktop.
Save cfchou/08065983e4c739165d8abcfe8420cb3e 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
foreground = yes
output = stunnel.log

[https]
accept=8443
connect=8000
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

$ ll /usr/bin/stunnel
lrwxrwxrwx 1 root root 8 Sep  7  2017 /usr/bin/stunnel -> stunnel4*

$ stunnel -version
stunnel 5.30 on x86_64-pc-linux-gnu platform
Compiled/running with OpenSSL 1.0.2g  1 Mar 2016
Threading:PTHREAD Sockets:POLL,IPv6,SYSTEMD TLS:ENGINE,FIPS,OCSP,PSK,SNI Auth:LIBWRAP

Global options:
debug                  = daemon.notice
pid                    = /var/run/stunnel4.pid
RNDbytes               = 64
RNDfile                = /dev/urandom
RNDoverwrite           = yes

Service-level options:
ciphers                = FIPS (with "fips = yes")
ciphers                = HIGH:+3DES:+DH:!aNULL:!SSLv2 (with "fips = no")
curve                  = prime256v1
debug                  = notice
logId                  = sequential
options                = NO_SSLv2
options                = NO_SSLv3
sessionCacheSize       = 1000
sessionCacheTimeout    = 300 seconds
stack                  = 65536 bytes
TIMEOUTbusy            = 300 seconds
TIMEOUTclose           = 60 seconds
TIMEOUTconnect         = 10 seconds
TIMEOUTidle            = 43200 seconds
verify                 = none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment