2
votes

I can't seem to get my server to connect over https.

I created a free Cloudflare account to get a free SSL certificate for a test server. I downloaded the origin certificate and key from Cloudflare onto my Ubuntu server running on the Google Cloud Platform.

https on port 443 is allowed in firewall options.

I tried to create a simple python https server as shown here:

from socketserver import TCPServer
from http.server import SimpleHTTPRequestHandler
from ssl import wrap_socket

httpd = TCPServer(('localhost', 443), SimpleHTTPRequestHandler)
httpd.socket = wrap_socket(httpd.socket, certfile='./cert.pem', keyfile='./cert.key', server_side=True)
httpd.serve_forever()

It runs with no errors but does not produce any output. I try to connect from the browser by accessing https://ip_address without specifying the port since I think https connects to port 443 by default.

I ran a simple http server on port 80 and that worked.

I'm expecting to see the basic html page in the directory connected over https, but I get ERR_CONNECTION_REFUSED in the browser instead.

1

1 Answers

2
votes

Change localhost to 0.0.0.0.

Localhost only accepts connections from inside the machine. This is the loopback address.

0.0.0.0 means bind to all available networks. This accepts connections from outside and inside the machine.