在我的简单蟒蛇套接字服务器上同时实现 HTTP 和 HTTPS

我希望我的访问者能够同时使用 HTTP 和 HTTPS。我正在使用一个简单的Python网络服务器,用套接字创建。我遵循了本指南:Python简单SSL套接字服务器,但它并没有那么有用,因为如果证书在其中一个客户端中不可信,服务器就会崩溃。以下是来自我的Web服务器的几行代码,它运行服务器:定义开始(自我):#创建一个套接字对象s = 套接字.socket(socket.AF_INET,套接字。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()


ABOUTYOU
浏览 80回答 1
1回答

慕雪6442864

让另一个服务(类似于nginx)处理https方面,然后将该服务配置为将代理反向代理到您的python服务器
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python