python - 在我的简单 Python 套接字服务器上实现 HTTP 和 HTTPS
问题描述
我希望我的访问者能够同时使用 HTTP 和 HTTPS。我正在使用一个使用套接字创建的简单 Python 网络服务器。我遵循了本指南:Python Simple SSL Socket Server,但它并没有太大帮助,因为如果证书不能在其中一个客户端中被信任,服务器就会崩溃。这是运行服务器的网络服务器中的几行代码: def start(self): # create a socket object s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# bind the socket object to the address and port
s.bind((self.host, self.port))
# start listening for connections
s.listen(100)
print("Listening at", s.getsockname())
while True:
# accept any new connection
conn, addr = s.accept()
# read the data sent by the client (1024 bytes)
data = conn.recv(1024).decode()
pieces = data.split("\n")
reqsplit = pieces[0].split(" ");
# send back the data to client
resp = self.handleRequests(pieces[0], pieces);
conn.sendall(resp)
# close the connection
conn.close()
解决方案
让另一个服务(类似于 nginx)处理 https 方面,然后将服务配置为反向代理到您的 python 服务器
推荐阅读
- flutter - 无法安装国际:^0.16.1
- python - Python 线程生命周期
- python - Airflow:如何为任务失败设置全局默认电子邮件?
- node.js - Visual Studio 中的编辑器无法识别对 node.js 中 url 中带有 ${} 的常量的引用
- php - HTTP ERROR 500:脚本“index.php”的标头格式错误
- sql - 触发器中的调用函数
- javascript - 使用 mongoose 管理 mongoDB 中的重复子文档
- google-apps-script - 我希望我在列的单元格内输入的值自动转换为负谷歌应用脚本
- java - jps、jstat、jstack 等命令显示“
未找到” - snowflake-cloud-data-platform - 在雪花中处理半结构化数据