1. Linux

1.2. Simple HTTPS Server

  • See https://gist.github.com/DannyHinshaw/a3ac5991d66a2fe6d97a569c6cdac534.

    sudo apt-get install python3-openssl
    openssl req -new -x509 -keyout key.pem -out server.pem -days 365 -nodes
  • Contents of the simple-https-server-python2.py file.

    # taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
    # generate server.xml with the following command:
    #    openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
    # run as follows:
    #    python simple-https-server.py
    # then in your browser, visit:
    #    https://localhost:4443
    
    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()
    python simple-https-server-python2.py
  • Contents of the simple-https-server-python3.py file.

    # taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
    # generate server.pem with the following command:
    #    openssl req -new -x509 -keyout key.pem -out server.pem -days 365 -nodes
    # run as follows:
    #    python simple-https-server.py
    # then in your browser, visit:
    #    https://localhost:4443
    
    #server_address = ('', 443)
    
    import http.server
    import ssl
    
    #server_address = ('localhost', 4443)
    #server_address = ('', 4443)
    server_address = ('', 8000)
    #server_address = ('', 443)
    httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
    ctx = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_SERVER)
    ctx.load_cert_chain(certfile="server.pem", keyfile="key.pem")
    httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True)
    httpd.serve_forever()
    python3 simple-https-server-python3.py

2. Windows

2.1. Simple HTTP/HTTPS Server

  • Enter the following commands at a Command Prompt.

    Start-SimpleWebServer