Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save astrojuanlu/13c2803bab300d2a8f0e117475a7a1cc to your computer and use it in GitHub Desktop.
Save astrojuanlu/13c2803bab300d2a8f0e117475a7a1cc to your computer and use it in GitHub Desktop.
Python 3 Simple HTTPS server with Certbot (for Let's Encrypt)
#!/usr/bin/env python3
# Create a basic certificate using Certbot (for Let's Encrypt) and Ansible:
# https://github.com/geerlingguy/ansible-role-certbot
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
domain = "example.com" # Edit with your domain
httpd = HTTPServer(("0.0.0.0", 443), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(
httpd.socket,
keyfile="/etc/letsencrypt/live/{domain}/privkey.pem",
certfile="/etc/letsencrypt/live/{domain}/cert.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