Last active
January 20, 2020 03:51
-
-
Save Graham42/b6dd41f7c5d079f484201336d4144fa6 to your computer and use it in GitHub Desktop.
Serve directory with https (SSL, TLS) self-signed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3-alpine | |
RUN apk --no-cache upgrade && \ | |
apk --no-cache add \ | |
openssl | |
WORKDIR /app | |
RUN openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes \ | |
-subj "/C=CA/ST=Ontario/L=Toronto" | |
COPY serve.py index.html /app/ | |
ENTRYPOINT ["python", "/app/serve.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Hello World</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
[ ! -z "$1" ] || (>&2 echo "missing target" && exit 1) | |
TARGET=$(realpath "$1") | |
docker build --pull -t serve-https . | |
echo Starting at https://0.0.0.0:8443 ... | |
docker run --rm -it -v "$TARGET":/app/web -p 8443:443 serve-https |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import http.server | |
import socketserver | |
import ssl | |
import os | |
PORT = 443 | |
web_dir = os.path.join(os.path.dirname(__file__), 'web') | |
os.chdir(web_dir) | |
Handler = http.server.SimpleHTTPRequestHandler | |
httpd = socketserver.TCPServer(("0.0.0.0", PORT), Handler) | |
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='/app/server.pem', server_side=True) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment