默认情况下,如何将HTTP重定向到HTTPS?
例如,如果我输入example_address.com,我想获得https://example_address.com
我的代码在
下面def run(server_class=HTTPServerV6, handler_class=Server, port=443):
server_address = ('::', port)
httpd = server_class(server_address, handler_class)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./secret_private_key.pem', server_side=True)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
答案 0 :(得分:0)
您可以尝试在端口80 中运行其他服务器,并将其请求重定向到您的https服务器。
这样的事情:
def runHTTP(server_class=HTTPServerV6, handler_class=Server, port=80):
server_address = ('::', port)
httpd = server_class(server_address, handler_class)
httpd.send_response(301)
httpd.send_header('Location','https://www.yourserver.com')
httpd.end_headers()