If you haven’t worked with uWSGI yet for setting up applications of different kinds – let me tell you it’s a Swiss knife. It supports applications written in Python, Ruby, PHP, Perl and recently Java and Go too.

One tool to run a lot of stuff – that means life is easier if you’re on the managing side of the system.

uWSGI has a module for Apache, which works with both 2.4 and 2.2. Redmine as you might be already knowing is a very good project management application (find out more about it on redmine.org).

The basic installation procedure, can be found in official Redmine documentation at redmine.org. I’ll post how I managed to get things working with Apache 2.4 using uWSGI.

Firstly, I’m using Gentoo on the server, my uWSGI is installed with Python, Ruby enabled.

This is the configuration in /etc/conf.d/uwsgi

# Enable threads? (1 = yes, 0 = no). The default is 0
#
UWSGI_THREADS=1

# The number of child processes to spawn. The default is 1.
#
UWSGI_PROCESSES=1

# The log file path. If empty, log only errors
#
UWSGI_LOG_FILE=/var/log/uwsgi.log

# Run the uwsgi emperor which loads vassals dynamically from this PATH
# see http://projects.unbit.it/uwsgi/wiki/Emperor
# The advised Gentoo folder is /etc/uwsgi.d/
UWSGI_EMPEROR_PATH=/etc/uwsgi.d/

# Additional options you might want to pass to uWSGI
#
UWSGI_EXTRA_OPTIONS="--auto-procname --master --vacuum --lazy-apps"

Basically it’s instructing uWSGI init script to launch it in Emperor mode (used to host multiple apps at the same time).

Now configuration for the redmine vassal /etc/uwsgi.d/redmine.ini :

[uwsgi]
socket = /run/uwsgi-redmine.sock
processes = 8
chdir = /var/lib/redmine
rails = .
env = RAILS_ENV=production
plugins = 0:rack_ruby19
rack = config.ru
cheap =
idle = 3600
uid = redmine
gid = redmine
chmod-socket = 770
chown-socket = apache:apache

Above configuration launches 8 processes when a connection is received to the socket and terminates them when it’s inactive for 1 hour, pretty enough for a low traffic site.

The plugins line says 0:rack_ruby19 , this is to avoid setting uWSGI modifier in Apache configuration. Without that line, you need to set uWSGI modifier in Apache configuration [and I don’t know what is that, see docs :P].

Apache configuration:

DocumentRoot /var/lib/redmine/public


 Options None
 AllowOverride None
 Require all granted


uWSGIsocket /run/uwsgi-redmine.sock

<if "!-e="" %{request_filename}="" ||="" %{request_uri}="=" '="" '"="">
 SetHandler uwsgi-handler

Initially I tried many workarounds like FallbackResource, using mod_fastcgi (and setting up uWSGI to listen on a fastcgi socket), also RewriteRules, but nothing seemed to work good.

The thing is, we need to set the uwsgi-handler for all pages that do not exist in document root. This thing is probably less seen, I found it in Apache docs by accident and now this is rolling.

Advertisements

Leave a comment