Skip to content

Instantly share code, notes, and snippets.

@nihui
Last active February 4, 2023 16:53
Show Gist options
  • Save nihui/c97a27b302bc56d554874af0f158d6df to your computer and use it in GitHub Desktop.
Save nihui/c97a27b302bc56d554874af0f158d6df to your computer and use it in GitHub Desktop.
simple https server
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl, os
os.system("openssl req -nodes -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj '/CN=mylocalhost'")
port = 8888
httpd = HTTPServer(('0.0.0.0', port), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='key.pem', certfile="cert.pem", server_side=True)
print(f"Server running on https://0.0.0.0:{port}")
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment