Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jorovipe97/3275c51cc5b6a276a2e994df59b24533 to your computer and use it in GitHub Desktop.
Save jorovipe97/3275c51cc5b6a276a2e994df59b24533 to your computer and use it in GitHub Desktop.
Python 3.x https server with SSL
#!/bin/bash
openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
import http.server, ssl
server_address = ('localhost', 4443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket,
server_side=True,
certfile='./server.pem',
ssl_version=ssl.PROTOCOL_TLSv1)
httpd.serve_forever()
# useful for running ssl server on localhost
# which in turn is useful for working with WebSocket Secure (wss)
# copied from http://www.piware.de/2011/01/creating-an-https-server-in-python/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment