Skip to content

Instantly share code, notes, and snippets.

@BjoernSchilberg
Last active September 7, 2018 11:23
Show Gist options
  • Save BjoernSchilberg/7289465 to your computer and use it in GitHub Desktop.
Save BjoernSchilberg/7289465 to your computer and use it in GitHub Desktop.
SSL HTTP server in Python 2

README

Generate a self-signed certificate compounded of a certificate and a private key for your server with the following command (it outputs them both in a single file named server.pem):

openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='server.pem', server_side=True)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment