PDA

View Full Version : Rails Deployment with Mongrel


gansos
01-23-2007, 04:24 AM
I've read that it's possible to do a Rails deployment using Mongrel with Apis. Using Capistrano, I can get to the point where the mongrel instances (2) are running, but I can't figure out how to proxy requests from Apache to these instances.

I've seen methods that use mod_proxy_balancer and mod_rewrite (specifically in "Agile Web Development with Rails 2ed"), but proxy declarations must go in httpd.conf, not .htaccess.

Is this type of deployment supported? If so, how can I make it work? If not, does anyone have any recommendations?

Matt
01-23-2007, 12:32 PM
Use the [P] flag to RewriteRule, e.g. RewriteRule ^/(.*)$ http://www.mydomain.com:mymongrelport/$1 [L,P]

gansos
01-24-2007, 09:07 PM
I've tried your suggestion, and it doesn't work. It appears that mod_rewrite isn't even working. I have the following in my .htaccess file in the default hosting directory:

RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:8000/$1 [P,L]

If I understand this correctly, it says "take everything after the / from the request and proxy it through 127.0.0.1:8000."

When I load up my domain I would expect it to invoke my "user" controller. However, I just get a 404 Not Found.

Edit: Invoking the mongrel instance through the command line works fine.

Matt
01-25-2007, 01:43 AM
Strip the / from rewriterule. Not quite sure what you were trying to accomplish with the rewrite rule when I just checked it out :). Also note that (a) 8000 isn't typically a permitted port, but (b) users are getting allocated port ranges in the 4xxx0 - 4xxx9 range with the new server of servers. xxx corresponds to the site index, which you'll know once the account is replicated on over. Just bear that in mind as something to change lest you incur my wrath in a couple of weeks.

cbergy
10-29-2008, 03:54 PM
Gonna bring this thread back for a short life. I'm having some strange issue running FCGI for 2 separate apps on the same server, so I'm switching one of them to Mongrel. I've setup the .htaccess to support the Proxy rewrite, however it's not playing nice with a rule above it. The line which checks for cached files appends .html to everything, so for instance Mongrel thinks it's looking for "the-process.html" instead of "the-process". Even without the [QSA] directive (I assume that's just for actual queries, '?=', etc.

Easy enough to just remove the cache check rule, but that may come in handy later on.

Here's the .htaccess file:


RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

RewriteRule ^/(images|stylesheets|javascripts)/?(.*) $0 [L]
RewriteRule ^$ index.html [QSA]
#RewriteRule ^([^.]+)$ $1.html [QSA] # Cache check, appending .html to path request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://carboncreative.ca:40340/$1 [P,QSA,L] # Mongrel proxy rule


Thanks!

cbergy
10-29-2008, 04:10 PM
Found a quick fix. Looks like if you replace the "/$1" in the Mongrel rewriterule with %{REQUEST_URI}, it works.

Cheers!