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
  • Save dwayne/f7c9631fa1e38abe2b8a to your computer and use it in GitHub Desktop.
Save dwayne/f7c9631fa1e38abe2b8a to your computer and use it in GitHub Desktop.

Revisions

  1. dwayne revised this gist Sep 28, 2014. 3 changed files with 21 additions and 14 deletions.
    11 changes: 11 additions & 0 deletions https_server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/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()
    10 changes: 10 additions & 0 deletions info.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    ## Credits

    Thanks to [Martin Pitt](http://www.piware.de/2011/01/creating-an-https-server-in-python/).

    ## Generating server.pem

    ```sh
    $ mkdir ~/.ssl && cd ~/.ssl
    $ openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
    ```
    14 changes: 0 additions & 14 deletions simple-https-server.py
    Original file line number Diff line number Diff line change
    @@ -1,14 +0,0 @@
    # 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()
  2. @dergachev dergachev created this gist Oct 17, 2013.
    14 changes: 14 additions & 0 deletions simple-https-server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # 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()