Saturday, April 28, 2012

redmine under nginx by passenger on debian

For the run redmine by passenger nginx must be compiled with passenger support. Many manuals offer to use passenger-install-nginx-module from passenger tarball. It reasonable solution if we use non-debian distro, because in Debian better use deb package than compiled from sources and installed to /usr/local.

For install redmine follow instruction on redmine.org

This article about deploy redmine under nginx by passenger.

Install passenger from repo:

cd /usr/src
apt-get source ruby-passenger
apt-get install ruby-passenger
apt-get build-dep ruby-passenger
build-dep offer to download about 37 Mb. If you don't want to install them all, you will need to experiment with dependencies such as libev-dev and else from list:
apache2-mpm-worker apache2-threaded-dev apache2.2-common asciidoc devscripts doxygen gem2deb graphviz libapr1-dev
libaprutil1-dev libboost-regex1.49.0 libcurl4-openssl-dev libev-dev libgcrypt11-dev libgnutls-dev libgnutls-openssl27
libgnutlsxx27 libgpg-error-dev libicu48 libidn11-dev libkdb5-6 libldap2-dev libp11-kit-dev librtmp-dev libruby1.9.1
libsource-highlight-common libsource-highlight4 libssh2-1-dev libtasn1-3-dev libxaw7 libxmu6 libxpm4 libyaml-0-2
ruby1.9.1 ruby1.9.1-dev source-highlight uuid-dev
But I hope, that you loving you time and just call build-dep.

You can use nginx from debian.org repos or from nginx.org repo. I prefered to use from nginx.org. So, use instruction from nginx download page to add next lines to /etc/apt/sources.list.d/nginx.list:

deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx
Next install nginx source and deps from deb-src by commands:
cd /usr/src
apt-get source nginx
apt-get build-dep nginx
So, now we have to unpacked sources directory in /usr/src, some like this:
nginx-1.2.0 ruby-passenger-3.0.11debian
In ruby-passenger source directory found ext/nginx, for example: /usr/src/ruby-passenger-3.0.11debian/ext/nginx. Add this path to nginx debian/rules file for compile. Now nginx debian/rules looks like this:

#!/usr/bin/make -f

#export DH_VERBOSE=1

%:
        dh $@

override_dh_auto_configure: configure_debug

override_dh_strip:
        dh_strip -Xdebug

override_dh_auto_build:
        dh_auto_build
        mv objs/nginx objs/nginx.debug
        ./configure \
                --prefix=/etc/nginx/ \
                --sbin-path=/usr/sbin/nginx \
                --conf-path=/etc/nginx/nginx.conf \
                --error-log-path=/var/log/nginx/error.log \
                --http-log-path=/var/log/nginx/access.log \
                --pid-path=/var/run/nginx.pid \
                --lock-path=/var/run/nginx.lock \
                --http-client-body-temp-path=/var/cache/nginx/client_temp \
                --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
                --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
                --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
                --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
                --user=nginx \
                --group=nginx \
                --with-http_ssl_module \
                --with-http_realip_module \
                --with-http_addition_module \
                --with-http_sub_module \ 
                --with-http_dav_module \
                --with-http_flv_module \
                --with-http_mp4_module \
                --with-http_gzip_static_module \
                --with-http_random_index_module \
                --with-http_secure_link_module \
                --with-http_stub_status_module \
                --with-mail \
                --with-mail_ssl_module \
                --with-file-aio \
                --with-ipv6 \
                --add-module=/usr/src/ruby-passenger-3.0.11debian/ext/nginx
        dh_auto_build

configure_debug:
        ./configure \
                --prefix=/etc/nginx/ \
                --sbin-path=/usr/sbin/nginx \
                --conf-path=/etc/nginx/nginx.conf \
                --error-log-path=/var/log/nginx/error.log \
                --http-log-path=/var/log/nginx/access.log \
                --pid-path=/var/run/nginx.pid \
                --lock-path=/var/run/nginx.lock \
                --http-client-body-temp-path=/var/cache/nginx/client_temp \
                --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
                --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
                --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
                --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
                --user=nginx \
                --group=nginx \
                --with-http_ssl_module \
                --with-http_realip_module \
                --with-http_addition_module \
                --with-http_sub_module \
                --with-http_dav_module \
                --with-http_flv_module \
                --with-http_mp4_module \
                --with-http_gzip_static_module \
                --with-http_random_index_module \
                --with-http_secure_link_module \
                --with-http_stub_status_module \
                --with-mail \
                --with-mail_ssl_module \
                --with-file-aio \
                --with-ipv6 \
                --add-module=/usr/src/ruby-passenger-3.0.11debian/ext/nginx \
                --with-debug

override_dh_auto_install:
        dh_auto_install
        /usr/bin/install -m 644 debian/nginx.conf debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/win-utf debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/koi-utf debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/koi-win debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/mime.types debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/scgi_params debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/fastcgi_params debian/nginx/etc/nginx/
        /usr/bin/install -m 644 conf/uwsgi_params debian/nginx/etc/nginx/
        /usr/bin/install -m 644 html/index.html debian/nginx/usr/share/nginx/html/
        /usr/bin/install -m 644 html/50x.html debian/nginx/usr/share/nginx/html/
        /usr/bin/install -m 644 debian/nginx.vh.default.conf debian/nginx/etc/nginx/conf.d/default.conf
        /usr/bin/install -m 644 debian/nginx.vh.example_ssl.conf debian/nginx/etc/nginx/conf.d/example_ssl.conf
        /usr/bin/install -m 755 objs/nginx  debian/nginx/usr/sbin/
Then you ready to build nginx deb package with passenger support. Go to nginx source directory and run debian/rules binary under fakeroot. It's can take a few times:
cd /usr/src/nginx-1.2.0
fakeroot debian/rules binary

fakeroot - fakeroot provides a fake root environment by means of LD_PRELOAD and SYSV IPC (or TCP) trickery.

Then you have normal and debug version of nginx debs in /usr/src. Install deb by call:

sudo dpkg -i /usr/src/nginx_1.2.0-1~squeeze_i386.deb

Add next lines to /etc/nginx/nginx.conf in http section:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger;
passenger_ruby /usr/bin/ruby;
I use debianic directory in /etc/nginx for sites config. So, create file /etc/nginx/sites-available/redmine.conf and make symlink for this config at /etc/nginx/sites-enabled/redmine.conf:
touch /etc/nginx/sites-available/redmine.conf
ln -s /etc/nginx/sites-available/redmine.conf /etc/nginx/sites-enabled/redmine.conf
redmine.conf will looks like this:
server {
    listen *:80;
    server_name redmine.example.com;

    passenger_enabled on;
    rails_env production;
    #set X_DEBIAN_SITEID "default";

    root /usr/local/share/redmine-1.1/public;

    location /plugin_assets/ {
        root /var/cache/redmine/default/plugin_assets/;
    }
}
Unfortunately I don't know how to set X_DEBIAN_SITEID for redmine in this case. If someone tells, I will add to this article.

You ready to use you redmine usually if you install and cofigure it by instruction from redmine.org

A few words about path for my redmine. At the begging of article I told about debian way and debs, but in fact I use redmine from svn and it's in production. So, it legacy project and it's works fine from /usr/local. But we using nginx for many projects, that's why I want to use nginx from deb but don't reinstall redmine from deb

Resources:

No comments: