goku2 asked:

Nitro + Apache2 on Gentoo box?

How can i setup nitro on a gentoo box? Is there a good tutorial on this?

(1 attempts)

Kashia answered:

h3. Installing Ruby and Rubygems

$ su -
# emerge -av ruby rubygems

h3. Install Nitro and Fastcgi

This also has to be run as root.

# gem install fcgi -y
# gem install nitro -y

This has now installed nitro and the FastCGI bindings on your system.

h3. Configure Apache

Add:

-D FASTCGI

to APACHE2_OPTS in /etc/conf.d/apache2

Uncomment the following line in /etc/apache2/conf/apache2.conf:

Include conf/vhosts/vhosts.conf

Add the Virtual hosts to /etc/apache2/conf/vhosts/vhosts.conf. (This might be /etc/apache2/vhosts.d/00defaultvhost.conf if your apache version if 2.0.55 or higher)

h3. Using Nitro

When you installed everything (maybe Postgresql or another database too?) You can use gen to create a stub Nitro project. This also adds configuration files in /path/to/app/conf where you can grab a Apache virtual host config from.

$ gen app ~/testproject
$ cd ~/testproject

In the public directory, there should be a .htaccess saying:

# Change as needed for your system.

AddHandler fcgid-script fcgi
#AddHandler fastcgi-script fcgi
AddHandler cgi-script cgi rb

# Redirect all requests not available on the filesystem 
# to Nitro. By default the cgi dispatcher is used which 
# is very slow. For better performance replace the 
# dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Nitro experiences terminal errors.
# Instead of displaying this message you can supply a 
# file here which will be rendered instead.
# 
# Example:
#   ErrorDocument 500 /500.html

ErrorDocument 500 "<h2>Application error</h2>Nitro failed to start properly"

That script is a bit different, from what is normal usually, in the public/ folder there are two files which are important: cgi.rb fcgi.rb. Rename them to dispatch.cgi and dispatch.fcgi so the right process gets started.

$ cd /path/to/app/public
$ mv cgi.rb dispatch.cgi
$ mv fcgi.rb dispatch.fcgi

At the top of the config file it configures which fcgi handler to use. I generally found it better to use fcgid and not fastcgi.

The last RewriteRule tells apache which file is used, the cgi file or the fcgi file.

Rating: 5