Nov 302016
 

Starting a HTTP server can be done using a one-liner in Python. Unfortunatelly there is no such way for SSL/TLS enabled servers. Here are 2 scripts that will do exactly this:

simplehttpsserver.sh

#/bin/bash
echo "Enabling simple HTTPS server on port 443"
if [ ! -f localhost.pem ]; then
  echo "Need to create self signed certificate"
  openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650 -nodes
  cat key.pem cert.pem > localhost.pem
fi
./simplehttpsserver.py
exit 0

simplehttpsserver.py

#!/usr/bin/python
import BaseHTTPServer, SimpleHTTPServer
import ssl

print "Starting HTTPS server on port 443"
httpd = BaseHTTPServer.HTTPServer(('localhost', 443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='localhost.pem', server_side=True)
httpd.serve_forever()

Put both in a directory of your choice and run the .sh to start your SSL/TLS enabled server.