This is sample code to run python CGI Web server with SSL. Note that i used CA signed certificate due to that i need to provide CA certificate as well in my python code which may not be necessary if you use self signed certificate.
#!/usr/bin/python
import BaseHTTPServer, SimpleHTTPServer,CGIHTTPServer
import ssl
import cgitb; cgitb.enable()
#httpd = BaseHTTPServer.HTTPServer(('web.tanu.com', 8000), SimpleHTTPServer.SimpleHTTPRequestHandler)
handler = CGIHTTPServer.CGIHTTPRequestHandler
httpd = BaseHTTPServer.HTTPServer(('web.tanu.com', 8000), handler)
handler.cgi_directories = ["/cgi-bin"]
httpd.socket = ssl.wrap_socket (httpd.socket,keyfile='./certs/key1.pem', certfile='./certs/cert.pem',ca_certs='./ca_cert.pem,server_side=True,do_handshake_on_connect=True)
handler.have_fork=False
httpd.serve_forever()
No comments:
Post a Comment