Start a Secure Web Server with CloudFlare SSL


  • Server with ubuntu (dunno if it works with other OSes)
  • Python3 (check if you have it already with python3 –version)
  • CloudFlare account
  • Domain name which has SSL activated with CloudFlare NameServers

Download SSL Certificate PEM and KEY

Go to CloudFlare Dashboard > SSL > Origin Server > Create Certificate

Copy PEM and KEY into a file named cert-and-key.pem* one after the other

Create a file* anywhere in your ubuntu server and paste that biscuit inside.

from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl

httpd = HTTPServer(('', 443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='/tmp/cert-and-key.pem', server_side=True)

Check the path of the pem file that created from cloudflare certificate

Then run it with sudo python3

Have a meditation session.

(*) String is optional
The python code is from and fixed by me.

Start the Discussion!Leave a Reply