Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HTTPS Server - All-in-One Secure HTTPS Server
#!/usr/bin/python
# server
# python https.py
#
# browser
# https://0.0.0.0:4443
import BaseHTTPServer
import SimpleHTTPServer
import ssl
import os
os.system("openssl req -new -keyout server.pem -out server.pem -x509 -days 365 -nodes -subj '/CN=www.pubnub.com/O=PubNub/C=US'")
httpd = BaseHTTPServer.HTTPServer( ( '0.0.0.0', 4443 ), SimpleHTTPServer.SimpleHTTPRequestHandler )
httpd.socket = ssl.wrap_socket( httpd.socket, certfile='./server.pem', server_side=True )
os.system("rm server.pem")
os.system("open https://0.0.0.0:4443/")
try: httpd.serve_forever()
except KeyboardInterrupt: pass
print("Server was closed by user.")
@stephenlb

This comment has been minimized.

Copy link
Owner Author

@stephenlb stephenlb commented Dec 9, 2015

python <(curl -L https://goo.gl/Rrko89)
@Steve1970s

This comment has been minimized.

Copy link

@Steve1970s Steve1970s commented Nov 27, 2016

Hi Stephen what OS do I need to run this server script ... I am thinking an APACHE LAMP server

@stephenlb

This comment has been minimized.

Copy link
Owner Author

@stephenlb stephenlb commented Oct 18, 2017

Yes you are correct. This needs to be run from a UNIX compatible system. Cygwin/Linux/MacOS

@28development

This comment has been minimized.

Copy link

@28development 28development commented Mar 2, 2018

I ran python https.py and I get following warning:
WARNING: can't open config file: c:/openssl-1.0.2l-win64/ssl/openssl.cnf Unable to load config info from c:/openssl-1.0.2l-win64/ssl/openssl.cnf Traceback (most recent call last): File "https.py", line 16, in <module> httpd = BaseHTTPServer.HTTPServer( ( '0.0.0.0', 4443 ), SimpleHTTPServer.SimpleHTTPRequestHandler ) NameError: name 'BaseHTTPServer' is not defined

Do I still need to set up something?

@stephenlb

This comment has been minimized.

Copy link
Owner Author

@stephenlb stephenlb commented Jun 11, 2018

You need to run this in a Docker Container or a Unix system like Linux/MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment