Redmine, Thin, and Apache over SSL

This article will walk you through setting up Apache to serve up redmine in a subdirectory over an SSL connection. It will use thin as the application server.

Let me start off by saying, what a pain in the ass. I fought with this for over an hour, trying to get everything to work correctly.

​The Goals:

  • Running on my SSL site, which is running Apache and protected by client certificates.
  • Running under the /redmine subdirectory on that site.
  • Served by Thin, running as my Apache user, and proxied by Apache

The Problems:

The real problem I encountered with this setup, after following all the usual guides I could find, was that when trying to access Redmine via /redmine, it would redirect to /login, rather than /redmine/login. Static assets also failed to load. Fortunately, this guide will tell you how to fix both.

Getting it all to work:

Here’s an overview of what we’ll be doing:

  1. Install Thin
  2. Set up Thin as a system service, and generate a configuration to serve up Redmine
  3. Configure Redmine and Thin so they know we want to serve up pages under /redmine, and not /.
  4. Configure Apache to proxy the requests to the Thin instance.

The first step is to install Thin and get that up and running. To do this, open up your Redmine Gemfile and add this to the bottom:

gem "thin"

Then, run

sudo bundle install

to get Thin installed. You can omit the sudo if your ruby is managed via rvm, or otherwise installed somewhere your user has write access to.

Next, we need to install Thin as a system service.  To do this, just run

thin install

and follow the distro-specifics for getting it to start at boot.  This also requires creating a config file for your redmine install.  Thin makes this easy:

thin config -C /etc/thin/redmine-2.2 -c /var/www/redmine-2.2 \
-u www-data -g www-data -e production --prefix=/redmine

What’s all that shit mean?

  • -C specifies the output filename for the config file
  • -c specifies the directory to change to when starting
  • -u / -g set the user and group that thin will run as
  • -e specifies the rails environment.
  • –prefix tells thin that it needs to prefix all url paths with /redmine. This is the solution to the first problem above; where it would redirect /redmine/login to /login

If you want, you can edit the file created by that command and edit anything.  It’s YAML.

Go ahead and start up thin via the system service:

sudo /etc/init.d/thin start

Next, we need to tell Redmine that it will be serving its assets (CSS and JS, images, etc) from /redmine, and not /.  To fix this, open up the file config/environment.rb and all this line to the bottom of it:

Redmine::Utils::relative_url_root = "/redmine"

Optional Test the configuration up to this point.  This is pretty simple; (assuming you’re using SSH) just forward a local port to port 3000 (the default; if you changed it, use that port) and load it up in your browser.  Trying to request / should give you an error.  Requesting /redmine should give you a Redmine login.

Provided that everything is working OK from the test above, now it’s time to setup Apache to proxy the connection to the Thin instance running on the machine.  Open up your Apache VirtualHost config and add the following Location block:

    ProxyPass           http://localhost:3000/redmine/
    ProxyPassReverse    http://localhost:3000/redmine/

Restart Apache

sudo apachectl restart

That’s all there is to it!  Now, you should be able to browse to your VirtualHost’s /redmine and see your login page.  Please leave any questions in the comments.

References:

 

1 comment

  1. Thanks a lot for this tutorial, it’s very good and it needs more visibility (a lot of redmine/apache2 tutorials purpose to use Mongrel which isn’t compilable any more with ruby 1.9.2+, see [1]) !

    Note that, if you have a HTTP 500 error (internal server error) when you try to log in, that there’s a bug in Debian/Ubuntu if the gem ‘rack’ version isn’t 1.4.5 [2]

    To resolve this bug, just run `gem install rack -v 1.4.5 && gem uninstall rack -v other_version` ( to determine actual version run `gem list –locale | grep rack` )

    [1] https://stackoverflow.com/questions/13851741/install-mongrel-in-ruby-1-9-3
    [2] https://github.com/backlogs/redmine_backlogs/issues/852#issuecomment-14986136

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.