Home > Uncategorized > Setting up an HTTPS (SSL) Server using CherryPy

Setting up an HTTPS (SSL) Server using CherryPy

With CherryPy (version 3.2.2) its pretty easy to quickly come with an HTTPS server in addition to an HTTP server. Basically, all you need to do as extra work is setting up the required SSL libraries (pyOpenSSL) and getting a certificate and a private key (which comes with the certificate). pyOpenSSL is an interface to OpenSSL library so first you need to set up OpenSSL then download and install pyOpenSSL from here. You may also need to add OpenSLL to your path variable so keep that in mind if there seems to be something wrong during setup. Also make sure that your Python is 32-bit or otherwise it can be very painful to set up openSSL and pyOpenSSL since they don’t have readily available 64-bit distributions. You can either buy a certificate (e.g. from Go Daddy) or generate your own self-signed certificate and use that. In my case since we were using a test server, I generated a self-signed certificate which I will talk about in another post.

After you have everything you can simply set up your server as shown below:


import cherrypy

class RootServer:
    @cherrypy.expose
    def index(self, **keywords):
        return "it works!"

if __name__ == '__main__':
    server_config={
        'server.socket_host': '0.0.0.0',
        'server.socket_port':443,

        'server.ssl_module':'pyopenssl',
        'server.ssl_certificate':'/home/ubuntu/my_cert.crt',
        'server.ssl_private_key':'/home/ubuntu/my_cert.key',
        # this is optional
        #'server.ssl_certificate_chain':'/home/ubuntu/gd_bundle.crt'
   }

 cherrypy.config.update(server_config)
 cherrypy.quickstart(RootServer())

In one of the next posts I will describe how to set up a server for uploading files that serves both over HTTP and HTTPS.

References: http://www.zacwitte.com/using-ssl-https-with-cherrypy-3-2-0-example

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: