
本文共 2713 字,大约阅读时间需要 9 分钟。
������������Flask���Hello World������������������������������HTTPS������
������������������������������Flask���������������������������������������HTTPS���������������������������������������������������������������������������������������
Step 1: ������Flask������
������������������������������������Flask���
pip install flask
Step 2: ������Flask������
������������Python������������������������������Flask���������
from flask import Flaskapp = Flask(__name__)@app.route('/')def hello_world(): return 'Hello, World!'
Step 3: ������Flask���������
������������������Flask������HTTP���������
if __name__ == '__main__': app.run(debug=True, port=5000)
������������HTTPS������������������������������ssl_context
���������
if __name__ == '__main__': app.run(debug=True, port=5000, ssl_context='adhoc')
Step 4: ���������������������
���������������������������������������������������Ubuntu 20.04 LXD���������������������
mkdir -p cacd ca
- ���������������
- ���������������������������CSR������
- ���������������
- ������������������
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
cp server.key server.key.org
���������ca
��������������������� server.crt
��� server.key
��������������������������������� server.key
������������������
Step 5: ������Flask���������������������������
���������Flask������������������������������
from flask import Flaskapp = Flask(__name__)@app.route('/')def hello_world(): return 'Hello, World!'# ������������������������app���������if __name__ == '__main__': app.run(debug=True, port=5000, ssl_context=(r'/path/to/server.crt', r'/path/to/server.key'))
���������r'/path/to/server.crt'
��� r'/path/to/server.key'
������������������������������������������
Step 6: ������Flask������������������
���������������
python app.py
������������������������ https://localhost:5000
���
���������������������������������������������������������������������������������������������������
sh -c "echo -e '\n\n*!' | tee /etc/ssl/certs/*.crt.pem && loca��octl --enable-crt /path/to/server.crt"
��� server.crt
������������������������������������������������������������������������������������������������������������������
Step 7: ������������������������������������
��������������������������������������������� CA ���895794UNDLE���������������������������������������������������������������������������������������������������������������
������
���������������������������������������������Flask���������������������������HTTPS���������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
