我有一个BaseHTTPServer
在Python中使用的可正常使用的HTTP服务器,因此我尝试添加一个SSL证书以允许使用LetsEncrypt进行HTTPS,现在它不会提供任何文件或响应。不会引发任何异常或错误,也不会提供任何内容。
server_address = ('0.0.0.0', 80)
httpd = HTTPServer(server_address, MyHandler)
# I can comment out the following line and it'll work
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=ssl_key, certfile=ssl_cert, server_side=True)
httpd.serve_forever()
#ssl_key = '/etc/letsencrypt/live/example.com/privkey.pem'
#ssl_cert = '/etc/letsencrypt/live/example.com/fullchain.pem'
MyHandler
以下是哪里:
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(204)
self.send_header("Content-Type", "text/html")
self.end_headers()
return
def do_POST(self):
self.send_response(204)
self.send_header("Content-Type", "text/html")
self.end_headers()
return
尝试从Web浏览器访问网站https://example.com
将返回标准的无响应“找不到服务器”。
我按照以下说明使用LetsEncrypt生成证书:https ://certbot.eff.org/#ubuntuxenial-other
sudo apt-get install letsencrypt
其次是:
letsencrypt certonly --standalone -d example.com
有什么办法可以让我轻松地找出问题所在?使用Python 3.5。如果需要,很乐意提供其他信息。
server_address = ('0.0.0.0', 80)
尝试从Web浏览器访问网站
https://example.com
将返回标准的无响应“找不到服务器”。
https://host
没有明确的端口规范意味着在https协议的默认端口443上访问服务器。但是,您已经将服务器设置为使用中的端口80 server_address
。
解决此问题的方法有两种:要么在URL中为https明确指定非标准端口,https://host:80
要么将端口的端口号server_address
从80更改为443。最后一种选择可能更好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句