Skip to content

Instantly share code, notes, and snippets.

@dineshshetty
Last active November 20, 2017 22:26
Show Gist options
  • Save dineshshetty/52d3b49af5a69fb2761950222902574a to your computer and use it in GitHub Desktop.
Save dineshshetty/52d3b49af5a69fb2761950222902574a to your computer and use it in GitHub Desktop.
Host SimpleHTTPServer over SSL
# Generate the certificate using openssl:
# openssl req -new -nodes -x509 -keyout server_certificate.pem -out server_certificate.pem -days 1
# Then launch the file using `python SimpleSSLHTTPServer.py` and navigate to https://127.0.0.1:8888/ to access the server
import sys, traceback
import BaseHTTPServer, SimpleHTTPServer
import ssl
def main():
try:
server = BaseHTTPServer.HTTPServer(('0.0.0.0', 8888), SimpleHTTPServer.SimpleHTTPRequestHandler)
server.socket = ssl.wrap_socket(server.socket, server_side=True, certfile='./server_certificate.pem')
server.serve_forever() #Handle requests until an explicit shutdown()
except KeyboardInterrupt:
print "Shutdown in progress..."
except Exception:
traceback.print_exc(file=sys.stdout)
sys.exit(0)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment