16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

数行でできる Django https有効化

Last updated at Posted at 2019-11-07

まずDjangoのプロジェクト正常に動いてることを確認してください

pip install django-sslserver
settings.py

INSTALLED_APPS = [
    ...
    'sslserver'
]
 ...
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = False
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
 ...

:point_up:SSL証明書を作ります


openssl genrsa -out foobar.key 2048
openssl req -new -key foobar.key -out foobar.csr
openssl x509 -req -days 365 -in foobar.csr -signkey foobar.key -out foobar.crt

サーバーを再度立ち上げます

python manage.py runsslserver 0.0.0.0:8000 --certificate /path/to/foobar.crt --key /path/to/foobar.key

以上です:hugging:

と言いても形上のhttpsなので、証明書はちゃんとした所に発行してもらいましょう

16
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?