搭建flask-web-https站点
Posted 51TesterHome
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建flask-web-https站点相关的知识,希望对你有一定的参考价值。
一、课题目的
使用flask 搭建一个免费且简单https的站点
二、实验条件
1、ca签发的自签名证书
2、python 环境
3、安装flask库
三、搭建步骤
3.1 自签名证书
3.1.1 创建CA根证书
openssl genrsa -out ca/ca-key.pem 1024
openssl req -new -out ca/ca-req.csr -key ca/ca-key.pem
openssl x509 -req -in ca/ca-req.csr -out ca/ca-cert.pem -signkey ca/ca-key.pem -days 3650
openssl pkcs12 -export -clcerts -in ca/ca-cert.pem -inkey ca/ca-key.pem -out ca/ca.p12
3.1.2 创建Server证书
openssl genrsa -out server/server-key.pem 1024
openssl req -new -out server/server-req.csr -key server/server-key.pem
openssl x509 -req -in server/server-req.csr -out server/server-cert.pem -signkey server/server-key.pem -CA ca/ca-cert.pem -CAkey ca/ca-key.pem -CAcreateserial -days 3650
openssl pkcs12 -export -clcerts -in server/server-cert.pem -inkey server/server-key.pem -out server/server.p12
3.1.3 创建client证书
openssl genrsa -out client/client-key.pem 1024
openssl req -new -out client/client-req.csr -key client/client-key.pem
openssl x509 -req -in client/client-req.csr -out client/client-cert.pem -signkey client/client-key.pem -CA ca/ca-cert.pem -CAkey ca/ca-key.pem -CAcreateserial -days 3650
openssl pkcs12 -export -clcerts -in client/client-cert.pem -inkey client/client-key.pem -out client/client.p12
3.2 flask DEMO
#-*- coding:utf-8 -*-
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "hello world"
if __name__ == '__main__':
app.run(port=5000,debug=True, ssl_context=('server/server-cert.pem','server/server-key.pem'))
3.3 访问flask web https站点脚本
以上是关于搭建flask-web-https站点的主要内容,如果未能解决你的问题,请参考以下文章 iphone / Objective c的最佳代码片段网站是啥[重复] spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段