python 3.10.4
Ubuntu 22.04 LTS (jammy)

This tutorial is for lab, testing and demo purposes and should not be used for production. Below is the sample code.

import http.server
import ssl

# Assign the port to be used.
PORT = 12345

# Assign the http server function that we are going to use to httpd.
# There are many way to write this, this the long version. You can make this better

httpd = http.server.HTTPServer((‘’, PORT), http.server.SimpleHTTPRequestHandler)

# Assign the ssl context to sslcontext
sslcontext = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)

# Load the self-signed certificate. You will need the cert and key that we manually generated. sslcontext.load_cert_chain(certfile=’demosec.crt’, keyfile=”demosec.key”)

# Start the HTTP Server will SSL enabled
httpd.socket = sslcontext.wrap_socket(httpd.socket, server_side=True)
print(“Starting HTTPS Server… on PORT “,PORT)


You can learn how to generate a self-signed certificate from the below link.