[Nitro] Nitro on Apache2 (Tutorial)

James Britt james_b at neurogami.com
Wed Oct 26 17:30:46 EDT 2005

Michael Fellinger wrote:
> I have encountered enough tutorials wich are platform-specific, but it feels 
> good when it is your platform that is in the tutorial...
> but you are right - let describing the installation of apache to the 
> apache-people.
> since ruby is platform-independent it shouldn't be too much of a problem to 
> get the most of the tutorials and guides independent as well. The problem is 
> not only the different flavors of linux, but the whole process is different 
> for example on windows. It requires a good skill of the author of the 
> tutorial to stay agnostic of the platform he/she is working on, and it 
> requires a lot of testing so it works on every machine like described.
> But regarding the Apache2-tutorial, could you please send me a copy of your 
> apache2.conf, or describe the process of getting nitro running on apache2?
> It would be a great help for me, and i would love to get the guide as well as 
> the configuration on my machine finished.
> thx in prev.
> manveru

I'm running this under Apache2 on a Red Hat Enterprise Linux box, as set 
up by EV1 hosting.  It is integrated with Plesk admin software, so the 
configuration is done in 2 parts.  (If you make changes through Plesk, 
it rewrites some files, so customization must be done in special 
#include files.)

So, the default httpd.conf file for my virtual host looks like this:
(Certain names and numbers have been altered, and I've stripped out some 
directory aliases that probably do not apply to most people)

(The IP number here is the IP of your Web server listens on.)

# httpd.conf
   ServerName   www.thevirtualdomain.COM:80
   ServerAlias   *.thevirtualdomain.COM:80
   # That's if you want to respond to any and all subdomains,
   # but you may need some DNS tweaking, which is a topic for
   # another day.  :)

   SuexecUserGroup      the_user  psacln
   ServerAdmin  "your.mail at gmail.com"
   DocumentRoot /home/httpd/vhosts/thevirtualdomain.com/httpdocs
/home/httpd/vhosts/thevirtualdomain.com/statistics/logs/access_log plesklog
   ScriptAlias  /cgi-bin/ /home/httpd/vhosts/thevirtualdomain.com/cgi-bin/
    <IfModule mod_ssl.c>
     SSLEngine off
   <Directory /home/httpd/vhosts/thevirtualdomain.com/httpdocs>
   <IfModule sapi_apache2.c>
     AddType text/plain .php .php4 .php3 .phtml
     php_admin_flag engine off
     Options -Includes +ExecCGI
   Include /home/httpd/vhosts/thevirtualdomain.com/conf/vhost.conf

So, basically, this tells Apache that the root for all requests to the 
domain thevirtualdomain.com is in the actual directory

However, depending on how you set up and develop with Nitro, you may 
have the root folder someplace else.  In my case, I need to tell Apache 
to look elsewhere for the root, so I out additional commands in vhost.conf

(This seems to be somewhat of a common approach.  Some admin define 
common defaults in htttpd.conf, with an include directive to an 
additional file where users can put custom directives.)

So, vhost.conf contains directives that either add on to what has 
already been configured, or, in the case of duplicate directives, 
override the previous value.  I first need to tell Apache where the real 
document root is, and then tell it the execute certain files as CGI:

# vhost.conf
   DocumentRoot /home/httpd/vhosts/thevirtualdomain.com/httpdocs/public
   <Directory /home/httpd/vhosts/thevirtualdomain.com/httpdocs/public >
     RewriteEngine On
     <Files ~ "\.(rb|rbx|cgi|pl)$" >
        SetHandler cgi-script
     Options -Includes +ExecCGI

Now, one last step.  I also have an .htaccess file in the 'public' 
directory (i.e, the document root for my web site).  The contents could 
go into either of those .conf files, but I find it easier to tweak the 
.htaccess file for rewrite hacks ( avoiding having to su, edit files, 
bounce Apache, and such.)

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

And one small note.  Certain server configurations are quite security 
conscious.  I learned, after much head scratching, that if I make ny 
*.rb files too-freely executable, they would not run (actully, they 
raised the useless "malformed header" CGI error).  Only chmod u+x was 
acceptable.  chmod ug+x or ugo+ was Bad.

I've not gotten fastcgi on Apache2 running yet, but do have a Rails app 
running on the same box with lighttpd + fastcgi.

Hope this helps, and apologies if people think it too off-topic.



http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com  - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com  - Playing with Better Toys

More information about the Nitro-general mailing list