Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Forked from dergachev/simple-https-server.py
Last active May 6, 2022 11:24
Show Gist options
  • Save RichardBronosky/644cdfea681518403f5409fa16823c1f to your computer and use it in GitHub Desktop.
Save RichardBronosky/644cdfea681518403f5409fa16823c1f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# 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 http.server
import ssl
httpd = http.server.HTTPServer(('0.0.0.0', 443), http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='./fullchain.pem', keyfile='./privkey.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1_2)
httpd.serve_forever()
#!/usr/bin/env python2
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate certificates with the following command:
# export EMAIL=admin@example.com
# export DOMAIN=example.com
# curl -sL https://gist.githubusercontent.com/RichardBronosky/644cdfea681518403f5409fa16823c1f/raw/get_letsencrypt_cert.sh | bash
# create symbloic links to the certificates
# ln -s /etc/letsencrypt/live/$DOMAIN/fullchain.pem ./
# ln -s /etc/letsencrypt/live/$DOMAIN/privkey.pem ./
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost or https://$DOMAIN
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='./fullchain.pem', keyfile='./privkey.pem', server_side=True, ssl_version=ssl.PROTOCOL_TLSv1_2)
httpd.serve_forever()
#!/usr/bin/env bash
# This script uses the concept at https://certbot.eff.org/#ubuntuxenial-other
# but overcomes the problem I consistently have of the server (at eff.org)
# not being able to connect to this machine. Given x_ prefix to correct github sorting.
mkdir -p /tmp/www
cd /tmp/www
sudo python -m SimpleHTTPServer 80 &
http_pid=$!
sudo certbot certonly \
--agree-tos \
--webroot \
--webroot-path $PWD \
--email $EMAIL \
--domain $DOMAIN
sudo kill --signal SIGINT $http_pid
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment