I need to graft some rails apps onto a website running apache 1.3 and
I must be missing something very obvious because I cannot get things
working properly. Here is what I need:
- The server must be running apache 1.3. A very large body of PHP
content is currently vended by the server through 5 vhosts and I have
neither the time nor resources to replace apache1 with apache2 or
lighttpd. Maybe someday, but not right now. - The rails apps cannot be their own vhosts. Basically, my apps must
be accessible via vhost.server.com/path/to/my/rails/app so they fit in
seamlessly with the existing server content and structure. - The setup needs to be as transparent as possible. The more stuff
that gets stuffed in config files and redirected through proxies the
more unmaintainable the server becomes. “Sysadmin” isn’t in my job
description, so I don’t need the added job security of a complex and
opaque setup.The PHP applications on the server are dirt simple
to maintain since deployment basically consists of running ‘svn
update’ somewhere in the server’s directory root. You don’t need to
read through config files or figure out what’s proxied to which
server. I’d like a similar setup for the new rails apps I’m trying to
deploy.
I had hoped those were simple requirements but I’m starting to feel
like such a setup is unachievable. I’ve just spent a great deal of
time over two days digging through this list’s archives and through
the wiki trying to get something working. Briefly, I’ve tried the
following two setups:
- Proxying my apps through apache to lighttpd instances. James Duncan
Davidson’s excellent Apache2 and Rails on Lighty pages served as a
reference: http://duncandavidson.com/essay/2006/01/railsonapache and
http://duncandavidson.com/essay/2005/12/railsonlighty - Grafting my apps by symlinking /public to a location in the
directory root and then building FCGI and configuring Apache. I used
these two wiki pages as guides:
http://wiki.rubyonrails.org/rails/pages/FastCGI and
http://wiki.rubyonrails.com/rails/pages/HowtoUseSymLinksToGraftRailsOntoYourWebsite
I was reluctant to start with the proxy setup since that was in
violation of goal 3, but almost all of the documentation out on the
net strongly encouraged that route if Apache had to be used for legacy
content. It also seemed simple to graft my app into a specific
subdirectory under the document root. Unfortunately, I simply could
not get it to work. Following
http://www.hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger,
I built lighty, FCGI and the Ruby FCGI bindings. I then followed
James’ guide to configure, test and deploy Rails on lighty and could
successfully connect to the server on a non-standard port. My app ran
just fine on lighty, so I stuck what I thought would be appropriate
proxy directives in the vhost’s apache conf file
ProxyRequests Off
ProxyPass /path/to/app/ http://lighty.server.com:8001/
ProxyPassReverse /path/to/app/ http://lighty.server.com:8001/
and restarted apache. Things looked great until I clicked on a link. I
was magically redirected from vhost.server.com/path/to/my/rails/app to
vhost.server.com. A bit of research and I discovered that I needed to
add
ActionController::AbstractRequest.relative_url_root =
“/path/to/my/rails/app”
to my config/environment.rb file. A quick lighty restart and my paths
were preserved. (Almost there!) However, whenever I clicked on a link
the server would load
vhost.server.com/path/to/my/rails/app/controller/method/id and never
redirect back to the app’s root as it should. Furthermore, the calls
to my controller’s methods didn’t have any effect: going back to the
root manually would bring things back in the same state. I double
checked all of my settings in apache and lighty, bounced both servers,
dug through the wiki and this list and eventually went to bed. I have
no idea why things don’t work.
Today I decided to take a different route and try the second setup. I
placed the symlink into apache’s document root, built mod_fcgi, added
LoadModule fastcgi_module libexec/httpd/mod_fastcgi.so
AddModule mod_fastcgi.c
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script fcgi
to the global apache config file and added
<Directory "/Volumes/Data/WebContent/htdocs/path/to/symlink">
Options +ExecCGI
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "<h2>Application error</h2>The regression
voting Rails application failed to start properly."
to the vhost’s config. (‘RewriteEngine On’ was already in the vhost’s
config.) I restarted apache and didn’t get any love at all. I can get
to the 404.html and 500.html files but the fcgi handler never comes
into play. I turned on +Indexes and could see the contents of /public,
so the symlink is working. The apache error file didn’t contain
anything juicy so I turned on mod_rewrite logging. The best I could
divine from that output was that the rewrite rules specified in the
Directory statement never got parsed… I also tried using the the
.htaccess file in /public by setting the vhost’s AllowOverride to
All, commenting out the Directory statement and restarting apache.
Same result, which didn’t surprise me too much. I have no idea why the
rewrites aren’t having any affect.
So, here I am at the end of two days of trying to deploy one rails
app. I’m starting to feel pretty stupid since I feel what I’m trying
to do would be fairly common and should be simple. Can anyone out
there help me out?
–
Ryan