Graham Edgecombe

Hosting Trac with Passenger and nginx

As well as being able to host Ruby applications with Rack, Phusion Passenger can also host Python applications with WSGI. This article shows how I set up Trac on Debian with nginx and Passenger.

I decided to use the Trac package available in the Debian repository, installing it is done with a simple apt-get command:

sudo apt-get install trac

You then need to create a Trac database. I decided to store it in /srv/trac but you can choose any location in which Passenger has read/write permissions. The command to run is:

trac-admin /srv/trac initenv

You will be asked a series of questions including the name of the project, the database connection string (I left this as the default SQLite option), the type of repository and the path to the repository. These values will vary depending on your current setup.

The next step is to deploy the static files to the document root we will use in nginx. I store all my websites in /srv/www so used the following command:

trac-admin /srv/trac deploy /srv/www/trac.grahamedgecombe.com

This will create two sub-directories: /srv/www/trac.grahamedgecombe.com/cgi-bin and /srv/www/trac.grahamedgecombe.com/htdocs. However, Passenger expects a folder called public and a script called passenger_wsgi.py. The best way to fix this is to create some symbolic links like so:

ln -s htdocs public
ln -s cgi-bin/trac.wsgi passenger_wsgi.py

Configuring Passenger generally requires lines like the following in the http block in your nginx.conf file:

passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.9;
passenger_ruby /usr/local/bin/ruby;

The appropriate lines will have been given to you as part of the Passenger installation procedure.

I also include the following configuration in the http block:

passenger_use_global_queue on;
passenger_user www-data;
passenger_group www-data;
passenger_friendly_error_pages off;
passenger_pool_idle_time 0;

You should also consider configuring the pool size with passenger_max_pool_size, passenger_min_instances and passenger_max_instances_per_app, the exact values you should use depend on how many applications you are running with Passenger and how much memory your server has.

Configuring a virtual server is relatively simple now and can be done by placing something like the following in your http block:

server {
  listen 80;
  server_name trac.grahamedgecombe.com;
  root /srv/www/trac.grahamedgecombe.com/public;
  passenger_enabled on;
}

Once that is done, reboot nginx and everything should work.

Comments

Post a comment