1. สร้าง self-signed certificate
$ openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
ในคำสั่งนี้จะได้ไฟล์ชื่อ server.pem เพื่อนำไปใช้งานต่อในขั้นต่อไป
2. สร้าง HPPS ด้วยภาษา Python
เนื่องจาก Python ได้มี ssl module ติดตั้งมาด้วยแล้ว ก็สามารถเรียกใช้งานได้เลย
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
SERVER_ADDR = 'localhost'
SERVER_PORT = 8000
httpd = HTTPServer((SERVER_ADDR, SERVER_PORT), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', server_side=True)
httpd.serve_forever()
ขอให้สังเกตุว่าผมไม่ได้ใช้ port 443 ตามแบบมาตรฐาน เพราะจะใช้ไม่ได้เนื่องจากเป็น reserved port ต้องใช้ตัวเลขอื่น จากนั้นก็บันทึกแล้วเรียกใช้งาน เราก็จะมี HTTPS server ไว้ใช้งานส่วนตัวแล้วSign up here with your email
1 ความคิดเห็น:
Write ความคิดเห็นNo more live link in this comments field
ReplyConversionConversion EmoticonEmoticon