Python 3 HTTPS Webserver [英] Python 3 HTTPS Webserver
本文介绍了Python 3 HTTPS Webserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道您可以使用
python -m http.server
然而,有一种简单的方法来保护与WebServer的连接,我是否需要生成证书?我该怎么做?
However is there a simple way to secure the connection to the WebServer, do i need to generate certificates? How would I do this?
推荐答案
首先,你需要一个证书 - 假设我们把它放在一个文件中 localhost.pem
其中包含两者私钥和公钥,然后:
First, you will need a certificate - assume we have it in a file localhost.pem
which contains both the private and public keys, then:
import http.server, ssl
server_address = ('localhost', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket,
server_side=True,
certfile='localhost.pem',
ssl_version=ssl.PROTOCOL_TLSv1)
httpd.serve_forever()
确保为 wrap_socket $ c指定正确的参数$ c>!
这篇关于Python 3 HTTPS Webserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文