Cobbler, uWSGI, and Nginx

I know. The title sounds like crazy talk. Why would you want to run Cobbler with uWSGI under Nginx? Well, I inherited a box that was already setup with Nginx and had Graphite running via uWSGI, so I wasn’t going to be the one setup Nginx to proxy to Apache.

Why not just run the perfectly good WSGI services Cobbler has directly? Well, Nginx’s mod_wsgi module is old and busted. It does, however, have support for the uWSGI protocol, and the uWSGI application server runs WSGI apps similarly to how you would use mod_wsgi in Apache. You end up with a leaner setup than you would probably get from a similar Apache config.

On to the good stuff!

The version of uWSGI I’m using is somewhat out of date, so I believe current versions use slightly different flags. That said, here you go.

uWSGI Services

The first is for the Cobbler services URLs and the second is for the Cobbler WebUI. These could be converted into uWSGI config files, but for quick and dirty, this works.

/usr/bin/uwsgi_python26 --wsgi-file /srv/www/cobbler/svc/services.py --socket 127.0.0.1:9090 --processes 4 --master --harakari 120 --max-requests 5000
/usr/bin/uwsgi_python26 --wsgi-file /usr/share/cobbler/web/cobbler.wsgi --socket 127.0.0.1:9091 --processes 4 --master --harakari 120 --max-requests 5000

Nginx Config

server { 
    listen 80;
    server_name ;
    charset utf-8;

    location ~ ^/cblr(?!/svc/)(.*)?$ {
        alias /srv/www/cobbler/$1;
    }
  
    location ~ ^/cobbler_track/(.*)?$ {
        alias /srv/www/cobbler/$1;
    }
  
    location /cobbler$ {
        alias /srv/www/cobbler;
    }

    location /cobbler_webui_content {
        alias /srv/www/cobbler_webui_content;
    }

    location /cblr/svc/ {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9090;
    }

    location /cobbler_api {
        rewrite ^/cobbler_api/?(.*) /$1 break;
        proxy_pass http://127.0.0.1:25151;
    }

    location /cobbler_web {
        rewrite ^/cobbler_web/?(.*) /$1 break;
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:9091;
    } 
 
    access_log /var/log/nginx/cobbler.log; 
}

That wasn’t so hard. Well, it was a pain in the butt figuring out, but that’s why I’m putting it here.

Leave a Reply

Your email address will not be published. Required fields are marked *