-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocal_https.py
More file actions
executable file
·28 lines (20 loc) · 836 Bytes
/
Copy pathlocal_https.py
File metadata and controls
executable file
·28 lines (20 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
# based on https://gist.github.com/rozifus/c529caf170699f117c53#file-local-ssl-server-py
# 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
from http.server import HTTPServer, BaseHTTPRequestHandler, SimpleHTTPRequestHandler
import os
import ssl
host = 'localhost'
port = 4433
httpd = HTTPServer((host, port), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='server.pem', server_side=True)
# cd to ./docs
os.chdir("docs")
print("now serving from https://{}:{}".format(host, port))
httpd.serve_forever()