Search code examples
pyramiduwsgi

Setup uWSGI as webserver with pyramid (no NGINX)


Most of the available tutorials show how to set up uWSGI with an upstream HTTP server (like NGINX). But uWSGI alone can act beautifully as router/proxy/load-balancer - refer this For my project, I didn't want to setup NGINX at this moment so I started off exploring the option of serving webpages through uWSGI. The answer here shows how to set it up with Pyramid.


Solution

  • I am using pyramid_mongodb scaffold, which I have modified to get it working on python3. See here for details. Assuming that we have a Pyramid project (created with pcreate -s pyramid_mongodb MyProject). Here are the uWSGI configurations needed in development/production.ini

    [uwsgi]
    http = 0.0.0.0:8080
    #http-to /tmp/uwsgi.sock - use this for standalone mode
    #socket = :9050
    master = true
    
    processes = 2
    
    harakiri = 60
    harakiri-verbose = true
    limit-post = 65536
    post-buffering = 8192
    
    daemonize = ./uwsgi.log
    pidfile = ./orange_uwsgi.pid
    
    listen = 128 
    
    max-requests = 1000
    
    reload-on-as = 128 
    reload-on-rss = 96
    no-orphans = true
    
    #logto= <log file>
    log-slow = true
    
    virtualenv = <path to virtual environment>
    
    #file = /path/to/pyramid.wsgi
    #callable = application
    
    need-app = true
    

    Also since we are using uWSGI we can comment out server portion from the ini

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

    To run the server use uwsgi --ini-paste development.ini