forked from lalaso2000/boar-map-beta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
36 lines (27 loc) · 1.08 KB
/
server.py
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
29
30
31
32
33
34
35
36
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
# httpsサーバーをローカルで立ち上げるスクリプト
# how to use
# 1. 下のコマンドを実施する
# openssl req -x509 -newkey rsa:4096 -sha256 \\n-nodes -keyout server.key -out server.crt \\n-subj "/CN=example.com" -days 3650
# 2. server.keyとserver.crtが出来上がる
# 3. python server.pyを実行
# 4. https://localhost:8000 が立ち上がる
def run(host, port, ctx, handler):
server = HTTPServer((host, port), handler)
server.socket = ctx.wrap_socket(server.socket)
print('Server Starts - %s:%s' % (host, port))
try:
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()
print('Server Stops - %s:%s' % (host, port))
if __name__ == '__main__':
host = 'localhost'
port = 8000
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ctx.load_cert_chain('server.crt', keyfile='server.key')
ctx.options |= ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1
handler = SimpleHTTPRequestHandler
run(host, port, ctx, handler)