Skip to content

Instantly share code, notes, and snippets.

@dwayne
Forked from dergachev/simple-https-server.py
Last active May 5, 2020 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dwayne/f7c9631fa1e38abe2b8a to your computer and use it in GitHub Desktop.
Save dwayne/f7c9631fa1e38abe2b8a to your computer and use it in GitHub Desktop.
Creating a simple HTTPS server in Python.
#!/usr/bin/env python
PORT = 8001
CERTFILE = '/home/dwayne/.ssl/server.pem'
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('localhost', PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile=CERTFILE, server_side=True)
httpd.serve_forever()

Credits

Thanks to Martin Pitt.

Generating server.pem

$ mkdir ~/.ssl && cd ~/.ssl
$ openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment