Search code examples
httpspyramidserver

pyramid pserve server as https


Is it possible to run Pyramid's pserve such that it starts an https server (for example https://0.0.0.0:6543)?

I would like to gear up my application for https locally if possible.


Solution

  • pserve uses waitress as it's server by default, however you can replace the server used by updating your .ini configuration file:

    [server:main]
    use = egg:waitress#main
    host = 0.0.0.0
    port = 5900
    

    For example:

    [server:main]
    use = egg:gunicorn
    host = 0.0.0.0
    port = 5900
    workers = 1
    worker_class = gevent
    

    gunicorn has support for SSL out of the box from looking at the documentation, and you could add the following to enable SSL:

    certfile=~/ssl/server.crt
    keyfile=~/ssl/server.key
    ssl_version=3
    

    This should allow you to run pserve and have an SSL enabled server. In most cases if you are deploying your project you would want to use nginx to proxy requests to your backend server, and have nginx do the SSL termination.