Python -m http.server 443 -- with SSL?(python-m http.server 443--使用SSL?)
问题描述
是否可以使用SSL证书创建临时Python3 HTTP服务器?例如:$ python3 -m http.server 443 --certificate /path/to/cert
推荐答案
不是从命令行,但是编写一个简单的脚本来执行此操作非常简单。
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
httpd = HTTPServer(('localhost', 4443), BaseHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(
httpd.socket,
keyfile="path/to/key.pem",
certfile='path/to/cert.pem',
server_side=True)
httpd.serve_forever()
Credit
如果您不局限于标准库并且可以安装pip包,则还有许多其他选项,例如,您可以安装接受命令行选项的uwsgi。
这篇关于python-m http.server 443--使用SSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!