Skip to content

Instantly share code, notes, and snippets.

@vivekgalatage
Last active August 20, 2025 10:12
Show Gist options
  • Select an option

  • Save vivekgalatage/d25a904693b33a16303059380d68a25c to your computer and use it in GitHub Desktop.

Select an option

Save vivekgalatage/d25a904693b33a16303059380d68a25c to your computer and use it in GitHub Desktop.
PythonServerForLocalHTTPS
# Generate SSL certficate
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem
# Run the python server
python3 https_server.py
import http.server
import ssl
host, port = ('localhost', 4443)
httpd = http.server.HTTPServer((host, port), http.server.SimpleHTTPRequestHandler)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile='cert.pem', keyfile='key.pem')
httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
print(f"Serving on https://{host}:{port}")
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment