Skip to content

Instantly share code, notes, and snippets.

@hakunamta00700
Forked from claudiosanches/django-runserver-ssl.md
Last active December 13, 2018 05:18
Show Gist options
  • Select an option

  • Save hakunamta00700/1c11aef440d5ef39bff8ab235a1a2626 to your computer and use it in GitHub Desktop.

Select an option

Save hakunamta00700/1c11aef440d5ef39bff8ab235a1a2626 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

이렇게 해봤는데 사실 잘 안되었다. 모바일에서 위치정보를 받아오려고 데스크탑에서 https 서버를 띄우고 같은 네트워크에 연결된 와이파이를 통해서 데스크탑에서 띄운 장고서버에 접속하려고 했는데 계속 에러가 남

error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

이 에러가 계속나서 찾아보니

sslVersion = all

로 바꾸란다.

그래서 바꿨더니

error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

이렇게 나오길래

client = no

여기서 변수들을 설명하자면

accept=8443

은 8443 포트로 데스크탑 서버에 접근하는 것을 말하는 것이고

connect=8001

그 접근을 8001포트로 연결한다는 것이다.

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

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