Creating a secure web server

Creating a secure web server

Postby PeterSteele » Thu Dec 05, 2013 7:11 pm

We've been using Python's SimpleHTTPServer module for use as a simple file server. We've decided to make the file server more secure by using https, and after doing some research I found lots of code to setup a secure web server in Python. None of the examples I've found though work.

The simplest code fragment I found was this:

Code: Select all
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='path/to/server.pem', server_side=True)

where server.pem is a pem file we've been using with another web server we're running. The Python code launches and runs without apparent errors but when I try to connect to the server using https://<server-ip>:4443 the browser prints the message "This webpage is not available." The Python code does not report any errors, and I can't even tell if the connection made it all the way through. I've tried various other versions of this code that I've come across but none of them work.

I have a Jersey-based web server running on another system that uses this same pem file and that works fine, but we want a small and light web server on this particular system, not a full blown web server like Jersey. As a test though I did setup Jersey on this system and it runs as expected, so I assume there is something wrong with my Python code. Can anyone explain what the problem might be?
Last edited by Yoriz on Thu Dec 05, 2013 7:13 pm, edited 1 time in total.
Reason: First post lock
Posts: 2
Joined: Thu Dec 05, 2013 6:44 pm

Re: Creating a secure web server

Postby PeterSteele » Fri Dec 06, 2013 1:07 pm

Turns out my pem file was wrong. Why one pem file works for my Jersey based server but not my Python based server I don't really know--I'm not a pem file expert. Our resident security guy generated a new pem for me and that solved the probem...
Posts: 2
Joined: Thu Dec 05, 2013 6:44 pm

Re: Creating a secure web server

Postby micseydel » Fri Dec 06, 2013 11:23 pm

Thanks for posting back the solution to your problem!
Join the #python-forum IRC channel on for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from :)
User avatar
Posts: 2919
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Return to Networking

Who is online

Users browsing this forum: No registered users and 4 guests