Running Redmine Project Management On nginx (Debian Wheezy)

Redmine is a project management tool written in Ruby. This tutorial explains how to serve Redmine with the help of thin (a fast Ruby webserver) through an nginx webserver on Debian Wheezy.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I have prepared a website www.example.com with the document root /var/www/example.com/web (Redmine will be installed there) that is owned by the user web1 and the group client0.

I have also prepared a MySQL database for Redmine with the name c0db1. The username is c0db1 as well, the password is FyZ5z4QGfhTf8.

 

2 Installing Redmine

First we install some prerequisites:

apt-get install thin ruby rake rubygems libopenssl-ruby libmysql-ruby librmagick-ruby ruby-dev libmysqlclient-dev libmagick-dev curl
gem install sass
gem install compass

Download the latest Redmine and copy it to our document root /var/www/example.com/web:

cd /tmp
wget http://www.redmine.org/releases/redmine-2.4.2.tar.gz
tar xvfz redmine-2.4.2.tar.gz
mv redmine-2.4.2/* /var/www/example.com/web
cd /var/www/example.com/web
chown -R web1:client0 *

Fill in the login details for our MySQL database:

cp config/database.yml.example config/database.yml
vi config/database.yml
[...]
production:
  adapter: mysql2
  database: c0db1
  host: localhost
  username: c0db1
  password: "FyZ5z4QGfhTf8"
  encoding: utf8
[...]

Install some other needed packages and fill the database:

apt-get install libmagickwand-dev
gem install rmagick
gem install bundler
bundle install --without development test postgresql sqlite
rake generate_secret_token
rake db:migrate RAILS_ENV="production"
rake redmine:load_default_data RAILS_ENV="production"

 

3 Configuring thin

Next we configure thin, our Ruby webserver that nginx will proxy requests to.

ln -s /etc/thin1.9.1 /etc/thin
mkdir /var/log/thin
chmod 755 /var/log/thin
cd /etc/thin

Create a thin configuration file that is named like the owner of the document root (web1):

vi web1.yml

Make sure to use the correct user (web1) in the log, pid, socket and user lines as well as the correct group (client0) in the group line. Use the correct document root in the chdir line:

---
chdir: /var/www/example.com/web
environment: production
timeout: 30
log: /var/log/thin/web1.log
pid: /var/run/thin/web1.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
socket: /var/run/thin/web1.sock
daemonize: true
user: web1
group: client0
servers: 1
prefix: /

Create the /var/run/thin directory (where thin will create its socket):

mkdir /var/run/thin
chown -R web1:client0 /var/run/thin

In order to make sure the directory exists when thin is started, we add the line test -e /var/run/thin || install -m 755 -o web1 -g client0 -d /var/run/thin to the /etc/init.d/thin init script (right after the SCRIPT_NAME line):

vi /etc/init.d/thin
[...]
DAEMON=/usr/bin/thin
SCRIPT_NAME=/etc/init.d/thin

test -e /var/run/thin || install -m 755 -o web1 -g client0 -d /var/run/thin

[...]

Now start thin...

/etc/init.d/thin start

... and take note of the socket it creates (/var/run/thin/web1.0.sock in this case) - we'll need it in the nginx configuration:

[email protected]:/etc/thin# /etc/init.d/thin start
[start] /etc/thin1.9.1/web1.yml ...
Starting server on /var/run/thin/web1.0.sock ...
[email protected]:/etc/thin#

If you're using Monit, you can add the following lines to /etc/monit/monitrc to make sure thin is always running:

vi /etc/monit/monitrc
[...]
check process thin with pidfile /var/run/thin/web1.0.pid
   start program = "/etc/init.d/thin start"
   stop  program = "/etc/init.d/thin stop"
[...]

Restart Monit afterwards:

/etc/init.d/monit restart

 

4 Configuring nginx

Next we must configure our nginx vhost through which we want to access Redmine. You must paste the following configuration into your server {} container (or the nginx Directives field if you use ISPConfig) - make sure you use the correct thin socket:

client_max_body_size 100M;

location / {
    proxy_set_header X-Reak-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    if (-f $request_filename/index.html) {
      rewrite (.*) $1/index.html break;
    }

    if (-f $request_filename.html) {
      rewrite (.*) $1.html break;
    }

    if (!-f $request_filename) {
      proxy_pass http://unix:/var/run/thin/web1.0.sock;
      break;
    }
}

That's it! Now visit your website, and you should be able to use Redmine. The default username is admin, the password is admin as well.

 

Share this page:

Suggested articles

5 Comment(s)

Add comment

Comments

By: Matthew Marable

First and foremost, awesome tutorial!!

Beyond the fixes in the nginx config as noted above, you may have an issue with broken SSL if you are using certain plugins which in my case would be "Redmine Local Avatars".

It seems as if the image links are non-SSL and Firefox will report that the connection to the site is not fully secured. To fix the issue, simply add the line below to your nginx config.

 

proxy_set_header X-Forwarded_Proto https;

 

By: Anonymous

Thank you for this howto. I think you have a typo in chapter 4:

proxy_set_header X-Reak-IP $remote_addr;

Should probably be X-Real-IP.

By: quang le

Thanks you so much ^^.

Your tutorial is awesome.

 

By: Steve

Excellent tutorial I've been able to get it setup the way I would like, I'm trying to use tcp sockets instead of file so I've set mine up differently in that aspect, though I can't seem to get it to work.. I'm getting this in my thin logfile, the application doesn't seem to want to work with it.

!! Unexpected error while processing request: uninitialized constant Rack::URLMap::PATH_INFO

It seems to be an issue with thin, because if I start it with webrick then Redmine loads?

 

[email protected]:/var/redmine$ bundle exec ruby bin/rails server --binding=0.0.0.0 --port=30000 webrick -e production

=> Booting WEBrick

=> Rails 4.2.1 application starting in production on http://0.0.0.0:30000

=> Run `rails server -h` for more startup options

=> Ctrl-C to shutdown server

[2015-03-29 22:22:54] INFO  WEBrick 1.3.1

[2015-03-29 22:22:54] INFO  ruby 1.9.3 (2012-04-20) [x86_64-linux]

[2015-03-29 22:22:54] INFO  WEBrick::HTTPServer#start: pid=14205 port=30000

Looked on Google for info about the error "uninitialized constant Rack::URLMap::PATH_INFO" no luck :(

Any ideas? :)

By: Peter Atkin

will the work with easyredmine? as were having serious with web access aka:http://www.redmine.org/boards/2/topics/10708?r=11519http://www.redmine.org/boards/2/topics/16653, our issues are pratoicaly identical and support from easyredmine is less than optimal.. so far...