Last active
August 20, 2025 10:12
-
-
Save vivekgalatage/d25a904693b33a16303059380d68a25c to your computer and use it in GitHub Desktop.
PythonServerForLocalHTTPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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