转: fastapi https 配置
python3 快速生成 https 所需证书
from OpenSSL import crypto, SSL
def generate_certificate(
organization="PrivacyFilter",
common_name="https://www.url.com",
country="NL",
duration=(365 * 24 * 60 * 60),
keyfilename="key.pem",
certfilename="cert.pem"):
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 4096)
cert = crypto.X509()
cert.get_subject().C = country
cert.get_subject().O = organization
cert.get_subject().CN = common_name
cert.gmtime_adj_notBefore(0)
cert.gmtime_adj_notAfter(duration)
cert.set_issuer(cert.get_subject())
cert.set_pubkey(k)
cert.sign(k, 'sha512')
with open(keyfilename, "wt") as keyfile:
keyfile.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8"))
with open(certfilename, "wt") as certfile:
certfile.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8"))
if __name__ == '__main__':
generate_certificate()
快速生成一个非安全的测试用证书,我运行了一下,发现可以在win10环境中运行上述代码生成证书和私钥。
运行fastapi
我的终端运行指令:
uvicorn tst-sql.main:app --ssl-keyfile ./cert/key.pem --ssl-certfile ./cert/cert.pem
原运行代码:
uvicorn.run("PrivacyFilterAPI:privacyFilterApp",
host="0.0.0.0", port=8000, reload=True,
ssl_keyfile="./key.pem", ssl_certfile="./cert.pem"
)
摘自:https://zhuanlan.zhihu.com/p/387353414
小工具 xca
xca下载地址:http://xca.hohnstaedt.de/
使用说明,见博客https SSL 自建证书的制作
转: fastapi https 配置的更多相关文章
- 烂泥:haproxy学习之https配置
本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb. 在前一段时间,我写了几篇有关学习haproxy的文章.今天我们再来介绍下haproxy ...
- haproxy学习之https配置
haproxy学习之https配置 原文 http://www.cnblogs.com/ilanni/p/4941056.html 如何配置https,以及https在实际生产环境中的应用. ...
- Apache https 配置指南
Windows Apache HTTPS配置创建下面3个目录: C:\Program Files\Apache Group\Apache2\conf\sslC:\Program Files\Apach ...
- nginx常用配置系列-HTTPS配置
接上篇,nginx配置系列 HTTPS现在已经很流行,特别是AppStore上线的应用要求使用HTTPS进行通信,出于安全考虑也应该使用HTTPS,HTTPS配置需要准备证书文件,现在也有很多免费证书 ...
- Tomcat8配置Https协议,Tomcat配置Https安全访问,Tomcat Https配置
Tomcat8配置Https协议,Tomcat配置Https安全访问,Tomcat Https配置 ============================== ©Copyright 蕃薯耀 2017 ...
- nginx普通配置/负载均衡配置/ssl/https配置
1.nginx普通配置 server { listen ; server_name jqlin.lynch.com; access_log /var/log/nginx/main.log main; ...
- apache https配置【转】
博文来源:apache https配置 参考博文:apache.nginx配置自签名证书 1. 确认是否安装ssl模块 是否有mod_ssl.so文件 2. 生成证书和密钥 linux下 步骤1: ...
- https进行配置以及http跳转到https配置
https配置: nginx配置 server { listen 443; server_name localhost; ssl on; root html; index index.html ind ...
- SSL 原理及 https 配置
目录 1. SSL 原理 1.1. SSL 简介 1.2. 主要概念 1.3. 建立安全连接的过程 2. https 配置 (以 nginx 为例) SSL 原理 SSL 简介 SSL (Secure ...
- Spring Boot SSL [https]配置例子
前言 本文主要介绍Spring Boot HTTPS相关配置,基于自签证书实现: 通过本例子,同样可以了解创建SSL数字证书的过程: 本文概述 Spring boot HTTPS 配置 server. ...
随机推荐
- 如何在Docker容器中使用systemctl启动服务
解决方案:使用--privileged参数初始化容器 docker run -d -p 80:80 -it --privileged centos:centos8 /usr/sbin/init doc ...
- vue特殊attribute-key
官方说明:如果不使用 key,Vue 会使用一种最大限度减少动态元素并且尽可能的尝试就地复用相同类型元素的算法.而使用 key 时,它会基于 key 的变化重新排列元素顺序,并且会移除 key 不存在 ...
- pip install 报错:Versioning for this project requires either an sdist tarball, ...
问题:Versioning for this project requires either an sdist tarball, or access to an upstream git reposi ...
- rsync备份服务器部署详情
rsync -avz --bwlimit=1024M /data/wanxhe rsync_backup@10.x.x.38::backup/gpu007/data/ --password-fil ...
- 环境声音分类的深度 CNN 模型
具体的软硬件实现点击 http://mcu-ai.com/ MCU-AI技术网页_MCU-AI 声音事件的分类精度与特征提取有很强的关系.本文将深度特征用于环境声音分类(ESC)问题.深层特征是通过使 ...
- pymysql的基本操作
1.Python3连接MySQL import pymysql pymysql.connect(host='localhost',user='root',password='1',database=' ...
- WPF+Emgucv实现在图像上画出感兴趣的区域 并进行掩膜获取 得到图像均值 和简单的 漫水填充
<Grid.RowDefinitions></Grid.RowDefinitions> <Grid> <UniformGrid Columns="2 ...
- OpenVSCode云端IDE加入Rainbond一体化开发体系
OpenVSCode 是一款基于Web 界面的在线IDE 代码编辑器,只需要PC端存在浏览器即可使用,更轻量,高效,简洁,其基础功能完全继承了微软出品的 VS Code ,可以通过安装扩展的方式继续加 ...
- windows下IPv6通信(C++、MFC)
Server #include <stdio.h> #include <Ws2tcpip.h> #include <winsock2.h> #define HELL ...
- react 装饰器
使用装饰器定义 装饰器是一种函数,写成 @函数名.它可以放在类和类方法的定义前面.react脚手架创建的项目默认是不支持装饰器,需要手动安装相关模块和添加配置文件. 安装相关模块 npm i -D c ...