1.首先我们需要生成证书文件cert及key
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /root/secret/server.key -out /root/secret/server.crt
2.python环境准备
确认之前已经正确安装Python3,Django1.8及以上
还需要安装的python库有:
执行pip install命令安装
python3 -m pip install django-extensions
python3 -m pip install django-werkzeug-debugger-runserver
python3 -m pip install pyOpenSSL
3.配置settings.py
INSTALLED_APPS末尾加入下面几行,并保存
'werkzeug_debugger_runserver',
'django_extensions',
4.开启服务,使用runserver_plus替换runserver
nohup /root/anaconda3/bin/python /root/mysite/manage.py runserver_plus 0.0.0.0:8000 --cert-file /root/secret/server.crt --key-file /root/secret/server.key --noreload >server.log 2>&1 &
其中:
nohup是忽略输入
–noreload是禁止django改动自动刷新(会导致开启两套服务调用时报错)
之后,直接访问即可:https://127.0.0.1:8000/
HTTPS部署指南

本文详细介绍了如何使用Python和Django框架部署HTTPS服务,包括生成证书、安装必要库、配置settings.py及使用runserver_plus启动服务的过程。
1633

被折叠的 条评论
为什么被折叠?



