Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You
More and more Rails developers are finding out that deploying a Rails application isn’t as simple as upload and rename; Rails apps work best when running all the time, and many Rails programmers are moving from traditional, shared hosts, like Dreamhost, to virtual private servers, like Rimuhosting, which allow them full control (and responsibility) of production servers.
Given this freedom, there are now a huge number of options available for deploying a Rails application, which is rare for such a new technology. So what to use? Apache + FastCGI? Lighttpd + FastCGI? SCGI? Apache 2? Litespeed? Mongrel? In what configuration? So many questions, so few answers. Here’s what I’ve been deleriously happy with, and how to do it yourself: Mongrel, Apache 2.2, and mod_proxy_balancer, using Capistrano to keep everything at your fingertips.
What the hell is Mongrel?
Mongrel is the hot new kid on the block. It’s a hybrid Ruby/C HTTP server designed to be small, fast, and brutally secure. It’s written by Zed Shaw, who is easily one of the most entertaining and delightfully cranky programmers I’ve ever read. (Zed, if you’re ever in the Bay Area, I owe you a pint.) While it’s a general purpose library, Mongrel is shaping up to be an amazing application server for Rails.
Sounds sweet. What’s Apache got to do with it?
Well, horses for courses. Mongrel is awesome at being a tight little application server for Rails, but when it comes to configurability, speed serving static files, and stability, Apache 2.2 beats the pants off Mongrel. But the main reason is that Rails does not play well with concurrency, and unless your code somehow magically gets around this, it will eat flaming death if it tries to do two things at the same time. So just Mongrel by itself would be slow at serving up static content like images, CSS files, etc., and it would necessarily be limited to a single request at a time, unless the main point of your Rails application was to publicly eat flaming death. (”It’s a feature!”)
So we’re going to be using Apache 2.2 as the front-end for Mongrel, which allows us to both serve up static content like it’s going out of style, but also to use a huge wealth of modules, like mod_deflate, which will improve your site’s responsiveness and download time. We’ll run a cluster of Mongrel servers locally, and route requests through Apache’s mod_proxy_balancer, which uses a sophisticated algorithm to make sure all the Mongrel servers feel equally loved.
Why not (Lighty|Pound|Litespeed|A Large Begonia)?
Apache is the heavy-weight in the web server world, and for good reason. It’s stable, fast, extensible, free as in Beery Speech, and all sorts of enterprisey. It’s gotten a bad rap in the Rails world, though, mainly due to its patchy FastCGI performance. It’s true, Apache + FastCGI is a horrible, horrible solution, unless your problem is “how can I waste my time on a dodgy server config?” in which case you shouldn’t be using the Intarweb while drunk. Finally, Apache currently has a great proxy balancer, which is why we’re using it.
This is not to speak ill of other front-end web servers, and you should feel free to use whatever you’re comfortable with. This article, though, is about how to set up what I’ve got set up, because I can vouch for it being awesome. Chip in on the comments if you’ve got a Mongrel band with a different lead singer and let us know how it’s going for you.
Okay, so what do I need?
I’m going to assume you’ve got Apache 2.2, Ruby 1.8.4, Subversion, and whatever database backend you need installed. That all depends on your operating system. Personally, I’ve had a great experience with Fedora Core 5, but I won’t make fun of you if you use Gentoo, Ubuntu, RHEL, Debian, FreeBSD, or whatever. Just make sure you can install and easily maintain your various pieces of software. Also, make sure you’ve got all the various low-level development tools, like a compiler or two, and the development packages for Ruby and such.
Your application has to be using either ActiveRecordStore, SQLSessionStore, or MemCached to keep track of session data. Files are the worst possible way to deal with sessions, and when you have more than one server reading and writing from the same file-based session store it’s gonna blow up big.
You should have a Capistrano script which will at least run the setup tasks correctly. If you need help with that, there are many blog articles and even a full-blown, if slightly outdated, manual on the damn thing.
Finally, none of this is going to work without root access (or an impossibly permissive server), and you’ll just piss off your admins if you try otherwise.
At this point you should have an Apache 2.2 “Welcome to Apache” style installation, and your Rails application should work just fine in WEBrick mode. If that doesn’t work, you’ve got problems which are best dealt with by tech support, IRC vets, or Friends Who Owe You Favors. If you aren’t at that stage yet, bookmark this page and get to work. I’ll wait until you’re ready.
Ready? Go!
1. Install Mongrel & Friends.
Because otherwise, the rest of this how-to is just going to be super awkward:
[server]$ sudo gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies
This will download, compile, and install Mongrel and its dependencies, daemons, a library which allows Mongrel to curl up at your server’s feet like a good little poochy poozle, and gem_plugin, which allows folks like yourself to write gem-based, module add-ons to Mongrel. It will also install mongrel_cluster, which contains a few tools which make managing a cluster of Mongrel servers easier.
Finally, it installs sendfile. I’ve already said that Mongrel is slow for static content, and it’s true. However, it’s a smart pup (and Zed’s a smart, smart man). In a proxying configuration, Mongrel will use sendfile, if it’s installed, to send Apache a reference to a file instead of reading it from disk and farting it out to Apache over a local HTTP configuration. This allows Mongrel to do the heavy lifting required of man’s best friend–running your Rails application–without getting bogged down in the minutae of CSS files, images, and Javascript files. Long story short: your site is faster. Many people skip installing sendfile, or don’t know about it, and because of this, they usally write Apache+Mongrel off as slow. Sendfile is the secret ingredient which allows Apache+Mongrel to be blazing fast.
I used to advise installing sendfile, but it doesn’t help–Apache serves the static content, so the 20%-or-so boost on static files is never seen–and it can even cause some pretty severe stability issues. So. No sendfile, and if you’ve got it installed, uninstall it, pronto. (This comes straight from Zed, who would know such things.)
Be sure to install at least mongrel_cluster (and thus, Mongrel) on your workstation–deployment via Capistrano will be complicated, otherwise, since you’ll have to reimplement all the code they’ve thoughtfully laid out for you already.
At this point you’re ready to get your Mongrel configuration on.
2. Mongrel: Sit! Lay! Restart!
First, you need to figure out how much memory you’ve got to spare, how much traffic you’re expecting, and how much money you’re willing to expend. An average Mongrel process can use between 15MiB and 40MiB of memory, depending on what your application does, and you need to figure out how many you can stuff into your server without popping it at the seams. Right now I’m running a decently-sized application with Apache, MySQL, and a cluster of three Mongrel servers in a 128MiB virtual private server with a bit of padding on top to keep the lid on. My advice is to start with two or three and build up to it. As you’ll see later, adding more clusters is stupid-easy. For now, we’ll assume that a cluster of three will do nicely.
Configuring the cluster
Pop open a terminal window, amble on over to your Rails project directory on your workstation, and crank out a cluster config file:
[workstation]$ mongrel_rails cluster::configure -e production \\
-p 8000 \\
-a 127.0.0.1 \\
-N 3 \\
-c /path/to/your/capistrano/setup's/current
This will add a file, mongrel_cluster.yml, to your config directory, which, when run, will launch a cluster of three Mongrel servers, starting on port 8000, listening on the local interface (and not to evil meanies on the internet).
Before we get to using it, however, we’ll need to make one small change for testing purposes. Open up mongrel_cluster.yml, and comment out the line with address: 127.0.0.1 on it (it’s YAML, so just add a hash at the beginning of the line). We’ll add this back in later, but for now we’ll want to make sure our cluster is behaving properly. Add mongrel_cluster.yml to Subversion, and check it in.
Configuring Capistrano
Mongrel_cluster comes with some drop-in replacements for Capistrano’s restart and spinner tasks. Open your deploy.rb and add the following to the top:
require 'mongrel_cluster/recipes'
Now add the following to your deploy.rb settings:
set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"
Make sure you don’t have any old code in your deploy.rb obscuring the dark, shining beauty of mongrel_cluster. Also be sure you add the :mongrel_conf statement after setting :deploy_to. Otherwise, as Jesse Clark notes in the comments below, you’re in for some weirdness.
Configuring the services
Finally, we need to register your Mongrel cluster as a system-level service, which will allow us to make sure it pops back up when your server reboots.
First, open a terminal window in your server’s services script directory. For most of you, this will be /etc/init.d/. Link the mongrel_cluster script from the gem directory to the services directory:
[server]$ sudo ln -s /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.1.3/resources/mongrel_cluster mongrel_cluster
[server]$ sudo chmod +x mongrel_cluster
Those you on Red Hat-based systems should add mongrel_cluster as a recognized service:
[server]$ sudo /sbin/chkconfig --level 345 mongrel_cluster on
If you’re running a Debian flavor, Ben Curtis assures me this works:
[server]$ sudo /usr/sbin/update-rc.d mongrel_cluster defaults
Those of you using otherwise will have to fend for yourselves. (Let me know how!)
Finally, link your mongrel_cluster.yml from your app’s config directory to /etc/mongrel_cluster:
[server]$ sudo mkdir -p /etc/mongrel_cluster
[server]$ sudo ln -s /your/rails/app/config/mongrel_cluster.yml /etc/mongrel_cluster/yourapp.yml
At this point, your server is rarin’ and ready to go.
Testing your cluster
Well, time to deploy, eh? Almost.
Before you begin, make sure your server can access your Subversion repository. Capistrano unfortunately doesn’t allow you to enter a password when Subversion prompts you for one, so go to a temporary directory and check out the entirety of your application. Subversion will remember your passwords once you’ve entered them.
Got your server playing well with Subversion? Then you’re ready to go!
In a loud voice, say something profound and memorable (”That’s one small step for Rails…”), and deploy that bastard:
[workstation]$ cap cold_deploy
This should checkout the latest version of your code, set up all the symlinks and other fun stuff, and finally start the Mongrel cluster. If it doesn’t, try running it with --trace and see what’s going on. Nine times out of ten, it’s some fiddly bit you forgot about in your haste to get this thing up and running.
If all went well (or was fixed after you let the magic smoke out), you should have three web servers running on your server:
- http://myserver.com:8000
- http://myserver.com:8001
- http://myserver.com:8002
Visit each one in your web browser, and make sure everything works. Fix all the problems you see until each works fine.
Closing up the cluster
Once everything is to your satisfaction, open config/mongrel_cluster.yml back up again, and uncomment the address: 127.0.0.1 line. Save and check in your changes, and re-deploy:
[workstation]$ cap deploy
Everything should go smoothly. Make sure the three 800x ports on your web server are no longer accessible–the only public entrance to your web site should be through Apache!
Now your cluster backend is done! Congrats. Go get a beer, or whatever refreshing beverage the grown-ups let you have. Time to get to work on the front-end.
3. Putting The Inukchuk In Apache
First, find out where your Apache config files are. If your distro isn’t a total crazy-pants, it’ll be something like /etc/httpd/ or /etc/apache2. Within that directory should be conf.d, which is where all of your server-specific config files go. We’re going to take a DRY approach to all this, and try to reuse as many bits of our config files as possible, to avoid the all-too-common problems associated with overlapping anything. Now, all files in the conf.d directory which end in .conf will be automatically included. Keep that in mind.
Removing the cruft
Your Apache installation no doubt includes a certain amount of cruft. Some of that you will need to remove immediately, like config files which block what we’re trying to do, and some of it you’ll want to remove later, like modules you don’t need.
In my installation, at least, the ‘Welcome to Fedora Core 5′ page that every URL produced was created by a default file, welcome.conf. It’s in the way, so out it goes:
[server]$ sudo mv welcome.conf welcome.conf.disabled
Let’s lay out the file structure I’ve been using to keep my config files sane:
- myapp.common
- The common portions of our configuration. Refactoring this out makes it easier to add additional VirtualHosts down the road (e.g., SSL) while still maintaining exactly the same configuration.
- myapp.conf
- The main entry, tying everything together to produce a working Rails app.
- myapp.proxy_cluster.conf
- A proxy balancer with which to interface with the Mongrel cluster.
- myapp.proxy_frontend.conf
- An (optional) HTTP front-end for managing the proxy load balancing configuration on the fly.
Feel free to replace ‘app’ with the actual name of your application.
And now, for the meat.
myapp.common
The common bits of configuration. This links a Directory or VirtualHost with the proxy-balancer, includes the proper mod_rewrite configuration for Rails, adds support for Capistrano’s enable_web and disable_web commands, and enables mod_deflate for most compressible formats.
ServerName myapp.com
DocumentRoot /var/rails/myapp.com/current/public
<Directory "/var/rails/myapp.com/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
# Make sure people go to www.myapp.com, not myapp.com
RewriteCond %{HTTP_HOST} ^myapp\.com$ [NC]
RewriteRule ^(.*)$ http://www.myapp.com$1 [R=301,L]
# Yes, I've read no-www.com, but my site already has much Google-Fu on
# www.blah.com. Feel free to comment this out.
# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
# Uncomment for deflate debugging
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog logs/myapp_deflate_log deflate
myapp.conf
This is pretty simple, it just ties the settings in myapp.common to a VirtualHost on port 80.
<VirtualHost *:80>
Include /etc/httpd/conf.d/myapp.common
ErrorLog logs/myapp_errors_log
CustomLog logs/myapp_log combined
</VirtualHost>
myapp.proxy_cluster.conf
This is loaded by Apache to configure a mod_proxy_balancer cluster mapped to the internal Mongrel servers.
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>
myapp.proxy_frontend.conf
This provides a front-end for the proxy load balancing, which you can access from inside your server at http://localhost:8080.
Listen 8080
<VirtualHost *:8080>
<Location />
SetHandler balancer-manager
Deny from all
Allow from localhost
</Location>
</VirtualHost>
4. Reboot And Go!
Time to kick over httpd and see if everything worked.
[server]$ sudo /sbin/service httpd restart
If all goes well, your web server is now configured as a Mongrel cluster backend to an Apache 2.2/mod_proxy_balancer frontend. You should feel happy.
5. Bonus Round! Secure server!
This one will depend greatly on your distro, but it does contain one super-important tip for getting a TLS/SSL version of your Rails app working in this setup.
Install mod_ssl, if you haven’t already
[server]$ sudo apt-get install mod_ssl
Replace the defaults in /etc/httpd/conf.d
My install added a file, ssl.conf to the conf.d directory. We’ll use this as a starting point, but let’s do it on our own terms:
[server]$ sudo mv ssl.conf ssl.conf.original
[server]$ sudo cp ssl.conf.original myapp.secure.conf
Now open myapp.secure.conf in your favorite editor (vi, right?), and scroll down to the VirtualHost it adds on port 443 (with Fedora Core 5, this was line 81). Inside the VirtualHost, add this:
Include /etc/httpd/conf.d/myapp.common
# This is required to convince Rails (via mod_proxy_balancer) that we're
# actually using HTTPS.
RequestHeader set X_FORWARDED_PROTO 'https'
That last bit is super important, especially if you’re using the ssl_requirements plugin from 37signals (and why wouldn’t you?). Otherwise, the Mongrel servers won’t know if an incoming request came in secure or not, which means you’ll have no way of knowing if you really should be processing that credit card or not.
Configure the certificates
Now, either look up the SSLCertificateFile and SSLCertificateKeyFile entries in myapp.secure.conf and replace those files with your cert and key, respectively, or edit the entries to point to where you have your cert and key stored.
Restart the server and test
[server]$ sudo /sbin/server httpd restart
Now see if that puppy works!
How well does this actually work?
Personally, it’s worked incredibly well. My “banging tin pots together” benchmarking with httperf indicated that where the Apache1.3+FastCGI setup on Dreamhost could handle ~30 reqs/sec before it would start dropping connections, the Apache2.2+Mongrel setup on a 128MiB Rimuhosting VPS can handle ~90 reqs/sec before things get hinky. In addition, the amount of downtime due to lost worker threads or fudged FastCGI connections was nil. The only times the site went down could be directly traced to me cutting first and measuring second.
Apache+Mongrel is shaping up to be the preferred deployment platform for Rails applications. Recently, the official Ruby On Rails site moved to Apache+Mongrel for their blog, wiki, and manuals site, all of which are much more responsive and have much lower downtimes. Rails Machines, an exciting new “rapid application deployment” hosting service for Rails applications, is using Apache+Mongrel for all their services. Rick Olsen, Rails Core member, has been running both his blog and Rails Weenie on ApacheLitespeed+Mongrel recently, and some people like Jonathon Weiss have moved large sites over to this architecture.
The great thing about this deployment architecture is that it leverages one of Rails’ greatest strengths: share-nothing scaling. All you have to do is add more boxes, and Apache+Mongrel makes that as easy as changing your deployment recipe and your myapp.proxy_cluster.conf file, then restarting the services. Your Mongrel clusters can span boxes and networks, making scaling a simple matter of plugging in hardware.
Long story short: it’s golden.
Thanks to…
I cribbed much of the initial Apache configuration and Mongrel ideas from Bradley Taylor’s Fluxura blog, as well as Jonathan Weiss’s article. Any errors I’m willing to acknowledge as my own, but leave a comment if you find something that doesn’t work for you! Finally, thanks to all the commenters with questions, corrections, and thanks. This article wouldn’t be nearly as accurate without you all. Thanks for trying to follow my instructions. ;-)
Enjoy!
June 20th, 2006 at 12:56am
If I recall Rick is running litespeed on his blog and rails weenie.
June 20th, 2006 at 1:36am
Coda, you are a Jedi master. Many thanks for this, most useful.
June 20th, 2006 at 5:52am
And I won’t make fun of you for using Fedora Core :)
Nice writeup, thanks!
June 20th, 2006 at 5:53am
Here’s the line to get Debian to set up the init script:
sudo /usr/sbin/update-rc.d mongrel_cluster defaults
June 20th, 2006 at 6:43am
Great article, when I’m ready to start experimenting I will be back…
Typo in the article if you are interested?
“My advice is to start with two or three and build up to it. As you’ll see later, adding more clusters is stupid-easy. For more, we’ll assume that a cluster of three will do nicely.”
“For more,” probably should have been “For now,”
June 20th, 2006 at 12:34pm
Great article! Just what I was looking for.
I did notice what appears to be an error, in this section:
Now add the following to your deploy.rb settings:
set :mongrel_servers, 3
set :mongrel_port, 8000
set :mongrel_environment, ‘production’
set :mongrel_config, “#{current_path}/config/mongrel_cluster.yml”
I believe that the last line actually needs to be:
set :mongrel_conf, “#{cur…
or at least, using the current version of mongrel_cluster it does
June 20th, 2006 at 12:47pm
Thanks a million, Steve! That bit of duplication always made my teeth itch, but I couldn’t get the config file to load on its own. Conf, not config. Awesome!
June 20th, 2006 at 4:29pm
[...] The unstoppable Coda Hale presents an amazing article about setting up a server with Mongrel, Apache, Capistrano, SSL support, etc. for solidly serving Rails applications. An extremely well written and solid guide. [...]
June 20th, 2006 at 5:23pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You (tags: ruby rails sysadmin mongrel) [...]
June 20th, 2006 at 5:29pm
Thanks for the resource, I found a couple things as I was going through it:
[workstation]$ mongrel_rails cluster::configure -e production \
-p 8000 \
-a 127.0.0.1 \
-N 3 \
-C /path/to/your/capistrano/setup’s/current
with this config command I get Errno::EISDIR.
Not having read the mongrel documentation (…) it took me a while to (incorrectly) assume that it was trying to write the config file to the path given to -C.
Much much later, I figured out that instead of giving it the path name to the config file, you might have meant to pass a lower case -c which would cause the mongrel_rails start commands to chdir to your deploy directory before executing which allows all the default paths to function correctly.
4 hours and one case change later, it was off to the races.
Another small point is that
set :mongrel_conf, “#{current_path}/config…
references current_path which references deploy_to and you’ll get odd results if you try to set mongrel_conf prior to deploy_to.
June 20th, 2006 at 5:40pm
Ack! Sorry about wasting four of your hours, Jesse! That was my left pinky getting a little eager with the shift button. And good point on the :mongrel_conf.
June 20th, 2006 at 7:27pm
Coda, now that I’ve installed Apache 2.2 and configured the cluster, all I’m getting is a blank page with ‘It Works’ writ across the top in large type — and I’m a bit at a loss as to what that means (or doesn’t mean), as I’d expect (or hope) to be seeing my app… any idea?
June 20th, 2006 at 8:20pm
Hmmm… that sounds like the default configuration of Apache, which you’ll need to disable, so your own configuration can show up.
In your conf.d directory, there is probably something like welcome.conf which you’ll need to rename to something like welcome.conf.disabled or somesuch.
If this isn’t the case, then your distro packagers felt like tossing modularity to the wind, and stuffed that portion of code directly into httpd.conf in the conf directory.
Failing that, you may want to fall back on the advice of #apache on FreeNode.net.
June 20th, 2006 at 8:29pm
I’ve spent the past few days setting up a very similar hosting environment and was thinking about making a write up myself. Now I see yours and I must say thank you. Your setup points out flaws I didn’t even think of in my own and encompasses (SSL in particular) more than I would have.
This is a really kickass article.
~smoil
June 21st, 2006 at 8:20am
[...] Coda Hale schlägt wieder zu: Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You. Eine Rundum-Sorglos-Anleitung zum Aufsetzen einer Rails-Anwendung mit Mongrel und Apache 2.2. Über das wundervolle Capistrano. Boochakayaya! [...]
June 21st, 2006 at 8:56am
It would have taken me quite a bit longer to get this far without this guide you have provided. I don’t consider the four hours wasted at all and I’m glad that I could contribute in some small way to your excellent article.
June 21st, 2006 at 10:11am
Nice writeup! Much of this is now automated using the railsmachine gem which I have released as open source. By default, the paths are configured to work with our server configurations, but you should be able to change the appropriate variables for your server.
To install:
“gem install railsmachine”
Quick start guide:
https://support.railsmachine.com/index.php?pg=kb.page&id=12
June 21st, 2006 at 10:49am
Coda,
Thanks for the great blog and plugins all the time… I checked out Rimuhosting and they look like a good fit for what I do. Are you hosting with them now? If you are tell me what domain your hosting with them and you will get a $15 referring credit.
Thanks,
Ben
June 21st, 2006 at 10:53am
Ben– I am indeed hosting with Rimuhosting, and their service has been flawless. Any and all downtime we’ve experienced with them has been strictly due to Sausagefingers McGunjumper (read: me, pushing buttons when I shouldn’t). If you want to toss me a credit, the domain is gpsgeek.com, but it’ll go to my employer, not me.
June 21st, 2006 at 11:10am
FYI mod_proxy_balancer was released with Apache 2.1 which is therefore the minimum apache requirement for this setup.
June 21st, 2006 at 5:29pm
[...] Rails, mongrel and Apache Enfin un tutorial pour installer Rails d’une façon efficace et compatible avec Apache, pour m’éviter d’avoir de multiples serveurs web. Et, finallement, ça ressemble vachement à ce qu’on fait en Java. (tags: development hosting rails ruby server software tutorial web apple) [...]
June 23rd, 2006 at 1:56am
Great post, thanks a lot for summing all this up. I wonder if this virtual hosting with 128MB ram is enough. I’ve been thinking of going virutal too, but was always scared by the low RAM they provide, especially with hungry Apache. Any problems with the size of the RAM? Machine must be swapping all the time….?
June 23rd, 2006 at 9:28am
You know, it’s not doing anything else but running Apache, Mongrel, and MySQL. It’s not the most roomy environment, but we honestly haven’t had any problems with it yet. Smaller sites can probably use two Mongrel processes, which would easily fit in a 96MiB VPS.
June 23rd, 2006 at 9:42am
Please be sure to read On Boot Initialization Setup in http://mongrel.rubyforge.org/docs/mongrel_cluster.html as it contains information about copying your config files to where the startup script can find them. You might want to add this information into the post as well.
June 23rd, 2006 at 9:55am
Crap, thanks JGeiger! I knew I forgot to write up a step.
June 24th, 2006 at 8:00pm
Hi - thanks for the great tutorial. In combination with Ezra’s ‘perfect rails stack’ article (http://www.brainspl.at/rails_stack.html) I nearly have my new dedicated server up and running.
I installed Apache2 from apt-get and all is good, except it doesn’t seem to include mod_proxy_balancer and I can’t seem to work out where to get it from. Any ideas on how to solve this last step would be greatly appreciated!
Thanks again.
June 25th, 2006 at 3:19am
Coda - thank you. A much needed article. ‘Best arguments I’ve read thus far for the Apache2/Mongrel setup. Looks like I need to rearrage a few things and dig in ASAP. I’ll let you know how it goes.
June 25th, 2006 at 8:53am
Ooops - Found out that the apt-get version of apache2 is 2.0 and not 2.2 which is the version which comes with mod_proxy_balancer!
Nuked the apt-get version and installed 2.2.2 from source and all works superbly now!
Thanks again for the great article :o)
June 25th, 2006 at 11:35am
I set this all up today (I’d previously been running Apache 2.0 + FCGI) and I’m loving it. I ran into a problem though. My Rails app lives in a subdirectory of my site, so for example my ProxyPass lines look something like this:
ProxyPass /test/ balancer://mongrel_cluster/
ProxyPassReverse /test/ balancer://mongrel_cluster/
That works, but the paths are all wrong because Rails thinks it’s at the root directory (which, as far as it’s concerned, it is), so it generates links to things like /controller/action instead of /test/controller/action, as it did when I was running it with FCGI. Does anyone have any idea how I might work around this issue? Maybe some clever mod_rewrite rules, or doing something with the routing, or somehow altering Mongrel’s configuration to place the Rails site in a subdirectory to match the Apache config? I’ll be experimenting with a few of these, but if someone has encountered this issue before I’d love to hear how you dealt with it.
June 25th, 2006 at 12:07pm
[…] A very accosting layout and a interesting discussion topic, do you provide any Web-based services to universities or students. […] - Sorry for the stupid question :-)
June 25th, 2006 at 4:19pm
To: Dan McCormack
I solved this issue by using the reverse_proxy_fix plugin.
ruby script/plugin install http://svn.napcsweb.com/public/reverse_proxy_fix
Lemme know if this works for you.
~Cyrus
June 25th, 2006 at 7:58pm
Cyrus: Perfect! With a little modification, that solved my problem exactly. I love the internet. Thanks :)
June 25th, 2006 at 10:41pm
Kudos, an excellent write-up indeed. Here are my notes/additions:
in gentoo the startup is:
$ sudo rc-update add mongrel_cluster default
and if you symlink (your symlinked) mongrel_cluster config you don’t have to worry about changing that one sitting in /etc/mongrel_cluster:
$ ln -s /path/to/your/capistranoed/app/current/config/mongrel_cluster.yml /etc/mongrel_cluster/yourapp.yml
I just got done converting one of our boxen from a lighttpd + externally managed fastcgi over to apache 2.2 mod_proxy_balancer + mongrel_rails on a smokin’ machine. I used siege to load_test her, and will be posting the results soon!
It would be cool to be able to somehow tell apache’s mod_proxy_balancer how many mongrel_rails exist dynamically — the hacker in me says there’s a way to build up those lines “http://127.0.0.1:8000 …” based on your mongrel_cluster file. Perhaps another day. ;-)
Thanks a bunch for the great field notes!
June 27th, 2006 at 8:45am
Hi there,
Great article!
I did run into a problem, and I’m not real sure what’s causing this. When I run “rake remote:cold_deply” cap freezes at the following line:
[192.168.0.200] executing command
** [out :: 192.168.0.200] Authentication realm: swaydev
** [out :: 192.168.0.200] Password for ‘dave’:
** [out :: 192.168.0.200] subversion is asking for a password
** [out :: 192.168.0.200] Authentication realm: swaydev
** [out :: 192.168.0.200] Username:
It won’t let me enter a username at this point. Everything just freezes.
Any ideas?
Thanks!
Dave
June 27th, 2006 at 8:46am
Woops… I meant:
“rake remote:cold_deploy”
(forgot the “o”)
-Dave
June 27th, 2006 at 8:48am
Dave–that’s a little-known gotcha of Capistrano’s. You need to make sure the account you’re using with Capistrano can access your Subversion repository for each app server of yours. Log into each and
svn co your_reposinto a temp directory. It’ll prompt you for the username and password, and once you’ve entered it successfully, it’ll remember it. Then you’ll be able to deploy without any problems.June 27th, 2006 at 2:11pm
Thanks Coda… I can’t believe I missed that!
-Dave
June 27th, 2006 at 4:52pm
Cluster works for me but not with Apache uhh!
Using the most basic setup I can think of to get this running. Created a basic rails app structure and configured mongrel. Started mongrel and can access the riding rails page from a browser at http://localhost:8000, http://localhost:8001, etc.
Problem is when using appache at http://localhost - it loads the riding rails page with no image, and when I click the “About your applictions environment” I get an Apache page: Service unavailable. Checking /etc/httpd/logs/myapp_errors_log shows: Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:8000 (127.0.0.1) failed
I’m transitioning (painfully) from a long Windows career to Linux so I’m sure I’m missing something silly here. Any ideas or places for me to look? I’ve checked all the directions in your post about 5 times and can’t find where I went wrong.
Thanks,
-Doug
June 27th, 2006 at 5:08pm
Doug–The “About your application’s environment” link will only work for local requests due to security reasons. In the production environment, none of the requests Mongrel receives from Apache will be considered local, and so Mongrel will issue a 403 error: permission denied. This seems like a likely source of your problem. You may want to add a controller to your Rails project and give it a simple
indexaction.If that doesn’t work, the problem probably lies in the way you have configured your proxy cluster in Apache. If you email me your config files for that, I’d be able to tell you more.
June 28th, 2006 at 10:41am
Hey Coda, I have a Spry VPS with Apache 2.0.46 and I’m too scared to try to upgrade it. Does Apache 2.0.46 have the necessary components to complete this walkthrough?
June 28th, 2006 at 6:38pm
Sorry, Jed. Only people with Apache 2.1 and up can play. You may want to talk to the folks in #apache about the advisability of compling Apache from scratch on your system. It may be easier than you think.
June 29th, 2006 at 8:07am
Daemonizing Mongrel…
I did have one minor niggle though. After restarting my server a couple of times during the aforementioned problems I had to restart Mongrel manually. I knew there was a better way to do it, but I didnt know how. Now I do
…
June 30th, 2006 at 3:12pm
Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You…
How to setup a web server, configured as a Mongrel cluster backend to an Apache 2.2/mod_proxy_balancer frontend….
July 1st, 2006 at 3:40pm
Another thing worth noting is that you should probably configure apache to deny access to the .svn subdirectories. Problem is that I can’t seem to get the information here to work: http://subversion.tigris.org/faq.html#website-auto-update with this configuration.
Anyone been able to successfully block access to .svn directories, if so where do you put the DirectoryMatch directive?
Cheers
July 7th, 2006 at 4:06am
Thanks a lot for this nice writeup, Coda, but there is one thing I don’t seem to get right. You mention that if you install the sendfile gem, mongrel won’t serve any static content but let apache do the work. So far so good, but shouldn’t the following rewrite rule from your myapp.common capture all static requests before mongrel even sees them?
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
July 7th, 2006 at 5:39am
Regarding comment #44: You can set the variable :checkout to “export” in your deploy.rb and capistrano will perform an svn export instead of svn co, so you won’t get a working copy and thus no .svn directories at all on your server.
July 7th, 2006 at 7:03am
Paul–I’m not sure if it’s the way I’ve got my routes mapped in my application, but my .svn directories aren’t publicly accessible. In terms of having Subversion automatically update things, you’re much better off using Capistrano.
Michael–two reasons: one, I’m pretty sure it helps with cached content, two, the Apache configuration still lets a few things slide. Regarding the first issue, I’m not positive, and regarding the second, fixing that is on my to-do list, and I’ll update this post when I fix that. In the meantime, it’s a very little bit of extra effort to make the worst-case scenario (Mongrel serving static content) a bit less worst-case.
July 7th, 2006 at 2:01pm
In regards to Doug’s post on June 27th, 2006 at 4:52pm. I was running into a similar issue:
(13)Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:8002 (127.0.0.1) failed
I found the issue to by SELinux. My dedicated server host setup my box with SELinux enabled and it was causing an issue between mongrel and apache. To disable SELinux temporarily, run the following command:
setenforce 0
Conversly, “sentenforce 1″ will enable SELinux again.
July 8th, 2006 at 10:07am
A minor thing — I believe the phrase is “a bad rap,” not “a bad wrap.”
July 8th, 2006 at 11:22am
Hi all,
I would like to use the apache2.2 and the mongrel cluser to serve more than one rails app (the apps run under different VirtualHost configurations). Do I have to create 3 mongrel processes for each VirtualHost entry or can I share (say 6-8 mongrel processes - yep I have enough Ram) between the apps ?
Thanks a lot
Great article BTW
Jens Carroll
July 8th, 2006 at 12:36pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda Hale [...]
July 8th, 2006 at 2:51pm
Paul–Thanks!
Jens–You can point many vhosts at a single cluster, but a cluster can only run a single application. You’ll need at least one cluster per application.
July 9th, 2006 at 4:03am
Thanks for the great tutorial!
A quick note for FreeBSD: Apache 2.2 should be installed with WITH_PROXY_MODULES=yes. i.e. cd /usr/ports/www/apache22 && sudo make WITH_PROXY_MODULES=yes && sudo make install .
And these modules should be added to the ones added by default in /usr/local/etc/apache22/httpd.conf:
LoadModule proxy_module libexec/apache22/mod_proxy.so
LoadModule proxy_balancer_module libexec/apache22/mod_proxy_balancer.so
LoadModule proxy_ftp_module libexec/apache22/mod_proxy_ftp.so
LoadModule proxy_http_module libexec/apache22/mod_proxy_http.so
LoadModule proxy_connect_module libexec/apache22/mod_proxy_connect.so
July 9th, 2006 at 9:21pm
One problem I have run into is that my static (cached) pages are correctly served through apache, but my assets like javascripts and css are still served through mongrel.
I think this has to do with all the requests automatically getting rewritten with a .html suffix ( RewriteRule ^([^.]+)$ $1.html [QSA]).
I am not enough of a mod_rewrite guru to figure out a solution, but I am sure someone else has.
July 10th, 2006 at 9:22am
To follow up on my previous comment, I have resorted to adding the following lines to my config.
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass /favicon.ico !
This ensures that my static files get served from apache, and not delegated to mongrel.
I found this solution on the mongrel mailing list archives.
July 11th, 2006 at 12:19pm
Ian–Thanks a million for that. I was following some of the threads there myself, and I’ve added your suggestions to the article.
July 11th, 2006 at 11:55pm
Great post Coda! A lot of good ideas. I was able to do an install Mac OS X Tiger (10.4.7) if someone’s interested.
Works greats so far.
Here’s the post: http://blog.nanorails.com/articles/2006/07/11/installing-rails-on-mac-os-x-tiger
July 12th, 2006 at 12:33am
[...] If you are only looking for the basics, Locomotive is probably what you need, if you want a grown-up rails setup on Mac OS Tiger, read on. [...]
July 12th, 2006 at 12:34am
For those of us not yet on Capistrano, but just using a SCM like perforce…what’s the nice way to restart the mongrels after a server push?
July 12th, 2006 at 8:01am
Seth, you really should take the time to set up Capistrano. It’s maybe 30 minutes of work and cap deploy means never having to say sorry. Also, it works with perforce.
Besides that, if you’ve registered your Mongrel cluster as a service, the easiest way is to just restart that and let mongrel_cluster do its job.
On Redhat-ish Linuxes:
On Debian-y Linuxes:
Or if you haven’t been playing around with services, you can always use mongrel_cluster itself:
But seriously… Capistrano.
July 12th, 2006 at 10:45pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda Hale Installing and deploying rails… (tags: rails rubyonrails webdev capistrano) Technorati Tags: [...]
July 13th, 2006 at 3:51pm
Finally rolled in some of the advice on mongrel-users to choose the mod_rewrite [P] option over the ProxyPass directives. That way all the static content gets served by Apache, not Mongrel.
(Took me long enough, jeez.)
July 14th, 2006 at 4:51pm
One small note on deploying using svn.
My svn servers are all behind tightly controlled firewalls, and the only way to get at them is using ssh+svn using private/public key authentication (yes, I know, I’ve been called paranoid before). In addition, my servers get no access to the internet unless I manually poke a hole in the firewall temporarily - this help prevent downloading things into my machines even if there’s a security breach. This completely precludes using svn for deployment. But all is not lost!
The way I deploy is I changed the capistrano recipe for checking out the code to do a local export to a temp directory, tar.gz it, and copy it over ssh to the server. Then on the server it is untar.gz’d into the same directory a checkout would put it.
So all that changes is the update_code recipe, the rest is the same and you get a more secure setup.
July 14th, 2006 at 5:42pm
Guy, you’re paranoid. ;-)
(Also, you could probably use Subversion over SSL using client certificate authentication, but since you’ve gone to all that trouble… nice hack.)
July 18th, 2006 at 5:21pm
Coda,
I see you said you “rolled in some of the advice on mongrel-users to choose the mod_rewrite [P] option over the ProxyPass directives” All I can tell is that you removed the ProxyPass directives. I see the following in your myapp.common:
# Redirect all non-static requests to clusterRewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-fRewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
So am I to assume that everything else is static and sendfile handles the handoff? How can I see which files are being served by sendfile/apache? The mongrel.log didn’t seem to tell me. Any clarification of how this whole process works would be great!
July 19th, 2006 at 12:58am
[...] Comme j’ai envie de faire du Ruby chez moi, et que la solution Mongrel+Apache2 m’apparaît comme impossible à mettre en place sur mon Ubuntu, je suis en train de passer doucement à lighttpd et honnêtement, je suis séduit. Séduit par la simplicité apparente de la configuration et ses possibilités avancées (rha, le enhanced virtual hosting, ça m’a l’air génial, ça). Par contre, pour l’intégration de langages de scripts comme le PHP, ça me pose un petit souci, car il faudrait que j’installe PHP indépendament d’Apache, ce qui est difficle quand Synaptic se bloque automatiquement à chaque lancement. Mais ça, c’est un problème propre à la distribution que je travaille à résoudre. Tout ça pour dire quoi ? Simplement que le blog risque de devenir, pour un moment, un intermittent du web et que je m’en excuse. [...]
July 24th, 2006 at 12:09pm
Holy crap, that’s a great tutorial. I’m ecstatic about my newly constructed Apache 2.2/Mongrel/Capistrano setup. Thanks so much!
July 25th, 2006 at 4:03am
[...] After reading this article I have became electric enough to try it on my current project that recently has gone to beta. [...]
July 27th, 2006 at 3:57pm
Great article. My new CRAM setup works *almost* perfectly. Anyone know why adding basic authentication into the Apache config doesn’t work? I get 404 errors for all static pages and no auth for the rails app.
July 29th, 2006 at 8:27am
I just got a VPS account on rimuhosting.com which has Debian Sarge installed which doesn’t have an apt package for apache2.2. Any tips on building it from source with mod_proxy_balancer?
July 29th, 2006 at 3:16pm
[...] I just completed switching over Pecuniarius to use mongrel cluster. It would have probably been easy except that I had Apache 2.0 installed so that meant I needed to upgrade, and naturally I took the long route to do that (build from source numerous times until I got it just right) but I finally got Apache 2.2 with modproxybalance installed and hooked it up to a brand spankin new mongrel cluster following the instructions on Code Hale’s blog (there is no way that’s a real name, but if it is its quite cool). This blog along with symphoniou.us are still running on single mongrel instances, but I’ll fix that soon. [...]
July 29th, 2006 at 7:09pm
Chad–those are indeed the changes. To see who’s serving up what, you can crack open a terminal and type
curl -v (the URL) > /dev/nulland it’ll print out the headers, which will include the server type. The general process is that Apache checks to see if the file exists on disk (if it doesn’t have a file extension, it assumes it’s .html). If it does, Apache serves it up. Otherwise, the request is proxied to Mongrel.July 29th, 2006 at 7:18pm
Jason–I’m totally calling this setup CRAM from now on. Sounds much more aggressive than LAMP. No idea about your authentication issues–it works fine for me.
Hammed–Sorry, haven’t done that. You may want to ask the folks at RimuHosting if you can switch over to Ubuntu, which has 2.2 packaged. Failing that, I’m sure the folks in #apache or #debian would have some decent advice on the matter.
July 31st, 2006 at 7:18am
Thanks Coda, I was able to build Apache 2.2 from source - I had assumed it to be more complex than it turned out to be. Later I found instructions for the same in this post on the rimuhosthing forms:
http://forums.rimuhosting.com/forums/showthread.php?t=230
I’ve successfullly tested mongrel clusters on the server (yay!) but with capistrano and the same mongrel_cluster.yml, mongrel doesn’t start and complains
!!! Path to log file not valid: log/mongrel.log
It appears to be a simlink issue but I haven’t figured it out yet. Any ideas?
August 1st, 2006 at 3:57am
guys, make sure to run
rake remote:setup
before
cap cold_deploy
or you’ll get the !!! Path to log file not valid: log/mongrel.log error I was getting. The shared/log folder is created by the setup task. Duh.
August 1st, 2006 at 7:45pm
guys…i’m a 2-month old newbie to the web-programming world…but Rails been a blast to play with…thou I can’t say for the deployment part (yet)…
in any case, has anyone bump into this error while doing that “cap deploy” (i have a mongrel_rails restart task in my deploy.rb)?
** [out ] ** You have sendfile installed, will use that to serve files.
** [out ] !!! PID file log/mongrel.pid does not exist. Not running?
** [out ] restart reported an error. Use mongrel_rails restart -h to get help.
Is that because when I subversion the project I ignored and removed the log files (as per the “HowtoUseRailsWithSubversion” guide)?
Coda: thanks so much for the post! I’m learning alot going thro the steps! So u’r from Berkeley too? Did you go to that awesome kite festival over the weekend?
peace folks..
August 1st, 2006 at 10:11pm
Michael–You may want to check out Hammed’s comment right above yours. Either you need to create the
logdirectory, you need to give write permissions on thelogdirectory to the user account that’s running the Mongrel processes, or you’re trying tocap deploywhen you should be runningcap cold_deploy(or evencap setup).(And yeah–I’m in Berkeley. Didn’t go to the kite festival, but I see them occasionally when I ride my bike along the bay to Richmond.)
August 3rd, 2006 at 2:21pm
Hey all — great tutorial so far, but I’ve hit a snag. I’m in the “Testing your cluster” section, and when mongrel_cluster tries to start, I get (output from only one of the 3 / it’s repeated 3 times):
———————————————————————–
** Daemonized, any open files are closed. Look at log/mongrel.8002.pid and log/mongrel.log for info.
** Starting Mongrel listening at 127.0.0.1:8002
** Starting Rails with production environment …
/usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel.rb:666:in `register’: undefined method `resolve’ for nil:Mongrel::URIClassifier (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel.rb:850:in `uri’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/bin/mongrel_rails:112:in `cloaker_’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel.rb:832:in `listener’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/bin/mongrel_rails:96:in `cloaker_’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel.rb:750:in `initialize’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/bin/mongrel_rails:83:in `run’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel/command.rb:199:in `run’
from /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/bin/mongrel_rails:235
from /usr/bin/mongrel_rails:18
———————————————————————–
… so, I’m basically unable to continue. Any thoughts?
- I noticed the comment about not using sendfile, so I’ve removed that
- mongrel 0.3.13.3
- mongrel_cluster 0.2.0
- daemons 0.4.3
- gem_plugin 0.2.1
I’ve inspected the code at /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel.rb line 666, and it looks like the classifier member isn’t getting initialized for some reason. :-\
August 3rd, 2006 at 4:40pm
ouch, i just set up my first cluster last night. I’m glad i came back here to reference the post again. Sendfile goes from the secret sauce to a bad influence? yikes…
August 3rd, 2006 at 10:08pm
To clear up my comment #78 … I was completely stumped. Then I recompiled ruby, and re-gem-installed all my gems, and then things worked. I had a hard lock-up on my laptop a few weeks ago, so *maybe* some core ruby files got mangled. Otherwise, I have not idea. Anyways, thanks for the tutorial — it was quite helpful.
August 4th, 2006 at 6:04pm
Coda,
i’ve got the mongrels doing their thing. its great. but apache mucks up the whole things. don’t think i have my virtualhosts right. could you please post a sample config of apache setup using name based virtual hosting?
August 7th, 2006 at 7:16pm
[...] I’m talking about Capistrano, Rails, Apache, Mongrel. Coda Hale wrote a great article on setting it up. I used his basic procedure, tailored it to my specific needs/personality, and voila! CRAM! [...]
August 7th, 2006 at 11:49pm
Mongrel is the way to go. after struggling with FastCGI and the mysterious hangs, we finally gave up and switched over. Aside from seeing Rails last year as the choice platform, this is the best decision we’ve made on the architecture side.
now crispynews is humming along beautifully
August 9th, 2006 at 6:49am
Hi Coda,
I am using Apache httpd 2.0.54 on Fedora Core 4.
I tried to follow your instructions as well as those from various websites.
However, getting Mongrel to run was a losing battle.
I tried to upgrade to httpd 2.2.x. I also tried to upgrade my Fedora installation to Fedora Core 5. But only managed to break everything else including Plesk.
Finally, I am back after a re-imaging of the server back at Fedora Core 4 with httpd 2.0.54.
Does Mongrel run with Apache 2.0.54?
If yes, can you please provide me with some help to setup Capistrano and SubVersion?
Currently I am running Rails using Apache+CGI.
Regards,
Ashish.
August 9th, 2006 at 1:38pm
[...] 3. Install mongrel (via http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/): sudo gem install daemons gem_plugin mongrel mongrel_cluster –include-dependencies [...]
August 11th, 2006 at 9:50am
[...] This post is heavily influenced by the Time For A Grown-Up Server web page. I highly recommend you read that web page too for a more in-depth commentary of why you would want to do this. [...]
August 13th, 2006 at 12:38am
Awesome stuff man!
August 14th, 2006 at 2:34pm
Managed to finally get Rails to run with Fedora Core 4, Apache 2.0.54 and SCGI.
Details of the configuration
August 15th, 2006 at 3:05pm
Is there any way to have specific directories point to something other than the mongrel cluster? For instance I have a /stats directory that I would like to maintain access to for web stats. But with the current setup it my Alias in apache for it is ignored. I tried adding ProxyPass /stats ! to my config but it doesn’t work. Any ideas?
August 17th, 2006 at 12:46am
Sean, I just resolved that problem today by just using a subdomain. My weblog is powered by mephisto, and i’m using mint for stats. I put mint on a subdomain and they’re living happily with each other.
August 23rd, 2006 at 8:09am
I’m having a ton of trouble getting my rails app firing. If I run just my mongrel cluster I can see my rails app going to http://10.104.0.121/website/index. I can also see the rolling on rails intro page at http://10.104.0.121.
However, once I fire up Apache, I still get the rolling on rails intro page, but my app doesn’t fire. I get the following errors in my log:
[Wed Aug 23 11:03:29 2006] [error] [client 10.70.120.45] no authorization providers configured
[Wed Aug 23 11:03:29 2006] [error] [client 10.70.120.45] File does not exist: /home/rails/prtrack/public/website
I don’t have the server dns setup yet, not sure if that has any impact. It just seems that Apache is not routing non-static requests to the cluster the right way.
I’d really appreciate any help, pointers or guidance in the right direction.
c.
August 25th, 2006 at 2:25pm
I have narrowed the problem down to rewrite rules. I have my rails app firing now. I am getting log information on rewrites, so I know that mod_rewrite is operating. It appears, however, that rewrite rules in my railsapp/public/.htaccess file are overriding those in my .conf file(s). Never does the rule invoking the proxy get executed. I have tried setting AllowOverride All/None for various subdirectories in my .conf file to no avail - either the server comes back with “file not found” or it executes the rails app via apache > dispatch.cgi and avoids the mongrel proxy.
Again, any assistance would be greatly appreciated.
August 25th, 2006 at 3:16pm
Cayce–You can uncomment the rewrite debugging levels in the configs and check the Apache logs for more possibilities. You may also want to check out the #apache channel on Freenode. They’re very helpful.
August 26th, 2006 at 6:59am
Turning on those logs is how I figured out what I have to this point. It’s very strange - I can see the various rewrite rules firing in the log file, but it’s only the ones from the rails app public/.htaccess file. It’s just never getting to/firing any of the rewrite rules from my .conf file(s) setup per your article.
In any event - it’s a problem with rewrite rules on my setup, not anything with your article, which successfully got me almost there. I appreciate the help. I’ll check out the freenode channel.
August 28th, 2006 at 3:01pm
Just an update - put my app in a sub-folder, used ProxyPass as noted by Dan M. above with Cyrus’ reverse_proxy_fix plug-in and everything is smooth sailing now.
August 30th, 2006 at 7:42am
I am probably missing something really simple here but I dont really understand what the -c parameter is pointing to in the cluster::configure command:
[workstation]$ mongrel_rails cluster::configure -e production \
-p 8000 \
-a 127.0.0.1 \
-N 3 \
-c /path/to/your/capistrano/setup’s/current
Path to my capistrano setup’s current what?
What path is that supposed to be pointing to? The path to my deploy.rb?
August 30th, 2006 at 8:20am
Ohhhhh, I get it… path to my capistrano setup’s “current” folder…
Sorry, dumb of me
August 30th, 2006 at 3:28pm
During deploy capistrano is unable to locate my executables (svn, mongrel_cluster, etc.). If I use
set :svn, “/usr/local/subversion/bin/svn”
in the deploy.rb file it executes the checkout fine, but still can’t find mongrel_cluster. Is there a way to explicitly set the location of your ruby bin directory? Or better yet, anyone know why capistrano is losing the path? The locations are in the path when I log in via ssh with the same user set in deploy.rb. Why aren’t they found by capistrano? I’m still a bit new to linux. Do scripts use a different path then the current user? If so, where can I set it?
August 30th, 2006 at 3:36pm
Just noticed a typo in my comment, mongrel_cluster should be read mongrel_rails.
if it helps the errors I’m getting from running cap cold_deploy:
bash: line 2: svn: command not found
and then when I set :svn, “/usr/local/subversion/bin/svn” to get passed that error I get
sudo: mongrel_rails: command not found
again, the commands causing the error run fine when I ssh with the user i’ve set in deploy.rb
August 31st, 2006 at 3:43am
Hi Code,
Thanks for the post, it was really helpful.
I have one small point which is that rewrite only checks for static files before the request is passed to Mongrel. The following code checks for directories as well.
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI}
Erin,
August 31st, 2006 at 9:34am
Regarding my previous comments (98 & 99):
I found creating symbolic links for the svn and mongrel_rails executables in /usr/bin works for now. I’d rather not have to do it this way, but it got me up and running so it’s acceptable until I have more time to figure out a better way.
August 31st, 2006 at 2:18pm
Nice article, really crucial information that’s hard to figure out otherwise. Why isn’t this article on Mongrel’s Apache Best Deployment Documetation?? It’s got my vote.
September 5th, 2006 at 6:59pm
[...] There is a lot more that can be done, especially in the ways of secure your server, blocking off access to the cluster from outside, this will be built upon. Thanks to the excellent Coda Hale guide, as well as Bryan’s guide from here. If you have any comments or suggestions, please leave them here or email kc0dxb@gmail.com [...]
September 10th, 2006 at 4:22pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You, by Coda Hale. I missed out the Capistrano bit here as I don’t use it yet, but if you do then clicky linky. [...]
September 11th, 2006 at 4:24pm
[...] I settled on a pretty clean setup today to make this kind of thing dead simple. I’m assuming you’re already familiar with how to setup mongrel clusters, and that you’ve got the balancer in Apache or whatever forward httpd server figured out and running. [...]
September 15th, 2006 at 7:36am
Coda,
I suspect this may be a capistrano problem but maybe not since no one else seems to have ran into this:
I am trying to do a test deploy where my “server” is the same as my workstation is the same as my svn repository (host = tenfwd.mcmaster.ca). I followed your instructions and everything worked fine up to the “cap cold_deploy” step. Executing this I get:
This seems to be telling me there is a syntax error in the “if” command but I have no idea where to find that particular command.
Help, please!
September 15th, 2006 at 10:49am
Re: post 106
Nevermind. After much gnashing of teeth and googling of web found out it was my shell: I use tcsh. Had to create another id that uses bash and add ’set :user, “username”‘ to deploy.rb.
Thanks for the article.
September 19th, 2006 at 1:27am
There is an issue with mod_rewrite when it finally passes the request along to the balancer…
If you have any escaped question marks (%3F) in your request, mod_rewrite will unescape them for you, so the balancer then parses what’s after the now-unescaped question mark as a query string (which is what you don’t want). Say for example you goto yoursite.com/users/user_name_with_a_%3F_in_it , that won’t work because rails will only see /users/user_name_with_a_ and the rest will be part of the query string…
I googled for a while and found a few places mentioning this problem. You can use:
RewriteMap escape int:escape
and then use the function ${escape:$some_var} to re-escape the un-escaped URI in your RewriteRule… but I haven’t been able to figure it out yet.
I tried a lot of things including ${escape:%{REQUEST_URI}} and none of them seemed to work.
Anyone have any ideas?
two helpful links:
http://mail-archives.apache.org/mod_mbox/httpd-users/200510.mbox/%3C8C29B2F93BAE9047A906EF6D6F9C5D439EFD77@exchange2k301.gaia.fr%3E
http://www.cherrypy.org/wiki/BehindApache
September 19th, 2006 at 11:19am
[...] OK, so it’s not a huge step, but we’re all agile around here, aren’t we? Hopefully now you’re comfortable with creating your own AMI and confident with the fact that the new image will boot. The next instalment will involve setting up a reusable Apache, mongrel and rails setup, much like is described in time for a grown up server since that’s pretty much my favourite rails deployment recipe. And we’ll create an AMI for that so that deploying a new rails app, with a little trickery from capistrano, is a turnkey solution. [...]
September 19th, 2006 at 11:19am
[...] OK, so it’s not a huge step, but we’re all agile around here, aren’t we? Hopefully now you’re comfortable with creating your own AMI and confident with the fact that the new image will boot. The next instalment will involve setting up a reusable Apache, mongrel and rails setup, much like is described in time for a grown up server since that’s pretty much my favourite rails deployment recipe. And we’ll create an AMI for that so that deploying a new rails app, with a little trickery from capistrano, is a turnkey solution. [...]
September 19th, 2006 at 6:25pm
[...] Another related change that happed at the same time: on the shared host I was running the rails app under lighttpd. In setting up the dedicated server, I switched to the hot new thang: apache mod_proxy_cache + mongrel. [...]
September 27th, 2006 at 2:57am
[...] Finally took the plunge to use Capistrano & Rimuhosting. Tried to do this with Dreamhost but it was all fubared beyond repair. Hence the disappearance of this blog as well. Most of you have no doubt read Coda Hale’s excellent write up. [...]
October 2nd, 2006 at 5:47am
[...] Create 4 files for your new application. (adapted from codahale blog) $ sudo touch myapp.common myapp.conf myapp.cluster.conf myapp.yml [...]
October 2nd, 2006 at 12:02pm
Hi am having the save problem as Dave had in post 96 + 97
. I have set up capistrano according to the agile rails development book (beta) but have no clue what setup folder you are reffering to.
Thanks!
October 3rd, 2006 at 1:34pm
I had problems using web services with this. Here is my thoughts on why, and how to fix:
When a connection is made, the wsdl contains the address and port to use for future communications( my speculation, I dont know much about webservices)
if you use 127.0.0.1:8001 as your balancer/proxy url, this is what gets sent on the wsdl. Now thats ip is your client machine, so you get Host actively refused the connection.
So I think you need to use a server name or the external IP of the machine.
ie your server is on 192.168.0.1
use this for your balancer
BalancerMember http://192.168.0.1:8000
BalancerMember http://192.168.0.1:8001
BalancerMember http://192.168.0.1:8002
October 4th, 2006 at 11:01am
It takes a little bit of time and effort to learn Capistrano’s functions, but once everything is working and you type in
rake deployfor the first time and your application is automatically updated as if by magic, you’ll never be able to do without it again. There’s also a compact one-page Capistrano cheat sheet here that you can download in PDF format which contains all the standard tasks, syntax examples, shell commands and directory structure which is VERY useful.October 8th, 2006 at 10:25pm
I am new to the web server business, to make this new phase of my life interesting my company has decided to cut back in my department; To counter this cut back I have hired a ruby developer with the notion that this new sleek fast language will be the answer to my prayers. This adds some new kinks to my life. First I must keep my Microsoft SQL data base so that means my best hope is to keep this all running in windows. That being said I was hoping that you might have some insight to deploy the above mentioned technologies in windows. Thanks for any help you might offer.
Thanks
Barry Chapman
October 9th, 2006 at 3:28am
For the deflate configuration, I don’t know how or where this is established, but my server gives javascript files the mime type application/x-javascript. It is worth adding that type to the AddOutputFilterByType directive, especially for a Rails application.
The prototype library is large, but you can reduce it to less than 25% of its uncompressed size. Here is the output from uncommenting the deflate logging.
"GET /javascripts/prototype.js?1160376830 HTTP/1.1" 12449/55149 (22%)
"GET /javascripts/effects.js?1160376830 HTTP/1.1" 7197/32871 (21%)
"GET /javascripts/dragdrop.js?1160376830 HTTP/1.1" 7085/29453 (24%)
"GET /javascripts/controls.js?1160376830 HTTP/1.1" 7230/28036 (25%)
While I was at it, I added image/bmp, since the page I was testing had a bitmap on it for some reason.
Thanks for the really nice and complete walkthrough. I’m running a mogrel cluster, oh yeah.
October 10th, 2006 at 6:18pm
Hi Coda, I’ve found a couple of problems with this setup, the first one being much more complex than the second! :)
1) If anyone is using imagemagick_tag to modify any of their images in realtime before displaying them on the page, they’ll get problems with Apache dropping the request for the modified image and calling it 404 without even giving the rewrite rules a go at sorting it out. Here is an example of one of the crude url’s that imagemagick_tag spits out:
As you can see, i think it’s trying to get around having to set up a custom route by encoding the path characters after the imagemagick method. Mongrel doesn’t mind this, but apache will just balk. Do you know of any way around this? It could affect quite a few people :)
2) Say your app stores images in a subdir of /public (like file_column does). Everytime you do a remote:deploy it wipes out the files that have been uploaded in the web interface because it’s symlinking a new version of the code (complete with an empty or sparse /public). Again, any thoughts on this problem?
Cheers,
Brendon
October 12th, 2006 at 1:38pm
Hello Guys! After setting up everything that was mentioned above my index.html gets rendered properly but when i remove it. I got a 403 error:
Forbidden
You don’t have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Does anybody has any idea why is this?
October 13th, 2006 at 12:24pm
Hi Everyone,
Thanks for the great walkthrough. I now have my server up and running, but have a few questions.
Has anyone been able to get this configuration running with multiple sites (both rails and others?). From my understanding whatever I place in the conf.d folder that has the extension of conf, will be included into the httpd.conf. From what I can see this becomes a problem with the files myapp.proxy_cluster.conf and myapp.proxy_frontend.conf . If i duplicate each of these files, for each virtual host, they will be run outside of the virtual host tag. For example, with the myapp.proxy_cluster.conf file, which points to each of the mongrel servers, if I have 2 clusters of 3 each, appache will hand off to each of the different mongrel clusters randomly, and therefore break the virtual hosting.
Would it be proper to rename these files, and then include them in the myapp.conf file, like we did with the myapp.common file? Or am I going about this all wrong?
Thanks Again!
October 15th, 2006 at 2:26pm
OK, after a week of struggling I’ve found out this important info regarding what Apache does when passing url’s to the cluster.
Firstly, if for some reason your app encodes slashes in the URL (imagemagick_tag) does this to hide the path to the image that it’s going to manipulate from the rails routing, then you’re stuffed if you use the Apache proxy option. Apache will either say 404 straight away (as encoding slashes is a security problem), or if you add this option to your virtual host: AllowEncodedSlashes On, it will unencode the slashes before it passes it to mongrel so it will still break as your routes won’t know what to do with the strange URL.
Secondly, Apache will also unencode an encoded + symbol (that is, in imagemagick_tag, when telling it what commands to apply to your image, it links the commands together with plus’s which it then encodes). Unfortunatley either apache or mongrel convert the + to a space, so your commands break.
To work around all of this I had to:
Change the way I used imagemagick_tag so that I could embed critical path information to my images in the URL string. I then had to create a special route for this new URL. I used the imagemagick_tag after_filter to then grab the file off the filesystem and output it as a text blob which imagemagick_tag then grabbed and made changes to.
To work around the + problem, I had to just use one command and then un-DRY the commands in the code by combining them in all the possible combinations that I had used in my views.
So yea, not an overly perfect solution but it works. I’d be interested to see if anyone else has encountered this kind of thing with apps that don’t quite fit the status quo.
October 18th, 2006 at 11:25am
Brendon, Capistrano creates a folder: “/app_root/shared/system”
Each time you deploy, the path “/app_root/current/public/system” is symlinked to that folder. So in other words, the system folder in your public folder stays the same from deployment to deployment. This is where you put any cross-deployment files, such as non-interface-related images or documents.
October 18th, 2006 at 6:55pm
There is a typo in your Apache config.
The following line:
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
must be written as
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
That is there must be a backward slash right before ‘bMSIE’.
The effect of this typo is that files that are not caught by previously listed rules, such as all *.css and *.js files are never deflated for MSIE users.
October 19th, 2006 at 8:09am
Thanks, Vlad. It was actually that way from the get-go (and is that way on my servers), but WordPress tends to eat leading slashes instead of, y’know, publishing what I wrote. Thanks for the heads up!
October 30th, 2006 at 8:43am
Hi
Problem with capistrano starting mongrel. I have the .yml file in [app]/shared/config. However, capistrano tries to start with -C [app]/current/config/mongrel_cluster.yml. This, of course, doesn’t exist, since that folder simply symlinks to latest release.
October 30th, 2006 at 9:13am
Well, I’d been trying to fix for ages, then …
My error was to create a ‘current’ directory manually. I deleted the whole directory structure redid setup, and heh presto current is a symlink - makes more sense that way!
October 30th, 2006 at 6:53pm
Hi, I’m trying to get things going on Mac OS X. Thus, I was wondering, what’s the best practice for setting up your local svn repository because Capistrano doesn’t work with file:/// from the documentation?
Thanks,
-Conrad
October 30th, 2006 at 7:41pm
Conrad: The server that you’re deploying to must be able to contact the machine on which your SVN repository resides. Your SVN repository appears to be on your workstation, which means that if you’re deploying to another machine, it has to be able to access your workstation. I’d suggest looking into the svn+ssh protocol, which allows Subversion to SSH into your machine and access the repository locally.
November 8th, 2006 at 6:34pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You (tags: ruby) [...]
November 16th, 2006 at 10:01am
This is a great post! (but you know this already!)
I’m getting multiple (11) mysqld processes running and I can’t work out why. I think it would open more but i’m out of memory.
I’m running apache 2.2. httpd.conf doesn’t say anything about the mysql server configuration. should it?
I don’t know where/how to configure this. Can anyone help? Thanks
November 17th, 2006 at 3:59pm
[...] http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-you/ [...]
November 19th, 2006 at 8:49am
You should also add
ProxyPreserveHost On
otherwise certain things such as the endpoint in a wsdl definition (using actionwebservice) will be broken
November 20th, 2006 at 6:48pm
Excellent, as usual.
I’m still playing around with the initial install, but Lighttpd + Mongrel + Pound seems to be working well for me.
November 28th, 2006 at 10:02am
Great article Coda - really helped me to get my Rails project off the ground. I’d just like to say that I had real problems getting the reverse_proxy_fix plugin to work for me (being a Rails noob and all). I looked through the comments posted here (thanks everyone) and ended up with the following change to my apache configuration (assuming an application called depot):
# Send the request (but do not allow access to the dispatcher or the cluster)# Note the use of trailing / this allows the mongrel_cluster prefix to work
ProxyPass /depot/ http://depot_mongrel_cluster:8001/depot/
ProxyPass /depot http://depot_mongrel_cluster:8001/depot/
ProxyPassReverse /depot/ http://depot_mongrel_cluster:8001/depot/
In addition, modifying the mongrel_cluster.yml as follows made everything burst into life:
prefix: /depotThanks again for the great article!
December 13th, 2006 at 6:57am
Hi,
I’m a bit lost with Capistrano here, I followed the instructions word by word but what I get is the following: http://pastebin.ca/277665
Any idea about what to do?
Regards,
Robert
December 13th, 2006 at 11:12am
Capistrano is very perfect for me and my work^
December 13th, 2006 at 12:13pm
Robert: It looks like you’re passing the update_code task some weird parameters, including :desc.
This is wrong:
This is right:
December 14th, 2006 at 2:42pm
Some bumps I hit that might help others:
On FreeBSD, I had to change a line in the capistrano gem on my workstation because it was not recognizing [[ as test. I changed line 34 to
if test ! -d #{configuration.release_path} ; thenAlso, ensure that your user is part of the wheel group and wheel is allowed in the sudoers file in /usr/local/etc/sudoers
Thanks very much!
December 16th, 2006 at 7:00am
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda Hale [...]
December 16th, 2006 at 7:51am
it might be a little off-topic but does any one knows of a benchmarking tool for comparing efficency of differrent combo’s?????
I can off course see the response times in firefox’s fasterfox to compare individual loads to check on mongrel+Apache(thanks to this article) and the lightpd+FastCGI(previous) combo, but that’s too simplistic & leaves lot of questions unanswered.
December 17th, 2006 at 8:09am
If your server’s linux distro doesn’t feature the required Apache version for makin a Mongrel cluster, have a look at http://www.rubyrobot.org/article/mongrel-apache-load-balancing-ruby-on-rails for instructions on building Apache 2.2.3 with proxy and load balancing enabled.
December 17th, 2006 at 6:10pm
I am trying to build fro ma Windows XP workstation and I can’t install mongrel_cluster. I get the following error:
“Failed to build gem native extension”
(as far as I understand, mongrel_cluster doesn’t exist for Win32).
But it looks like a don’t really need mongrel_cluster: only the recipes for Capistrano.
So, my two questions:
1) is it possible to build from a Windows workstation?
2) can I fake a mongrel_cluster installation by copying the recipes somewhere?
December 18th, 2006 at 6:08am
[...] I went through the steps outline here to get Mongrel up, running and configured. Again, another problem. I had configured everything properly (I thought), but I kept getting ‘403 Forbidden’ errors when trying to access my sites. [...]
December 22nd, 2006 at 8:35pm
[...] As I planned to deploy behind Mongrel and Apache; I had to upgrade to Apache 2.2 (to get proxy_balancer), Ruby 1.8.5 (to get the latest Mongrel 0.3.13.4 with Mongrel_cluster 0.2.1) and Capistrano for remote deployment. Apart from the source, the best resource for all this text file tweaking is at Coda Hale’s site, with some extra double-cross checking from Rimuhosting’s wiki. [...]
January 4th, 2007 at 9:29am
Cyrille - Good luck i am 99% sure that Capistrano will not work with windows I have successful set up Apache 2.2 running a Mongrel Pack (mongrel Cluster) but I could not find any nice or easy setups. You will have to do it all manually. But it I am actually running it on Windows 2003 R2 *(on a virtual server) and it runs GREAT!!! I am still having a few issues with ProxyPass and images but i am will figure it out.
January 4th, 2007 at 10:03am
Cyrille-
sorry i did not read your questions yes you can mimic a cluster *(i am a newbie ) so forgive me if i do not use the correct ruby terms but i believe you use Apache load balancer and then what the way i am faking a mongrel pack is with a little app called firedeamon it allows you to run an exe as a service **( i know it can be done with rails or a number of other ways but i found them to be flaky) with this app i set up 8 single instances but it works well and sort of mimics the whole pack my config for the firedeamon app is
Short name = Railsapp1
Display Name = Railsapp1
Description = Mongrel Pack #1
Executalbe: = c:\ruby\bin\ruby.exe
Working Directory = c:\web\App1
Parameters: = c:\ruby\bin\mongrel_rails start -d -e development -p 6000
I have ironed out most of the kinks and it seems to be a solid set up.
January 6th, 2007 at 9:53pm
[...] I’m currently putting together a Rails, Mongrel, Apache configuration (maybe capistrano….). I was glad to find this article while looking how to use apache, with mod_proxy_balancer, and Mongrel instances. [...]
January 9th, 2007 at 12:47pm
Hi -
Just got this all working with a perforce repository, and FC6. Tookl about 4 hours, but have my first scaffolded table running… weee :) …
There were a few hiccups, this article and everyones feedback helped out a great deal. On FC6 out of the box I had to modify the setenforce for SELinnux (Security Enhanced Linux) in order to allow apache to talk to mongrels. I found the easy way to do this is and preserve on reboot was to modify /etc/selinix/config to SELINUX=permissive. There are probably more secure ways to do it, but this box is behind all types of firewalls so not too worried.
Thanks for the great article!
Tony
January 11th, 2007 at 8:33am
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
January 17th, 2007 at 9:30am
Great article, Coda. I probably owe you a pint once I move to the Bay Area. I documented my setup process for this type of Apache / Mongrel cluster on Ubuntu following most of your steps. Where I lost you is in what exactly Capistrano does. Does it just do the heavy lifting of pushing what’s in your Subversion out to some production server? If so, nifty, if not, confusing. Thanks again,
Richard
January 17th, 2007 at 10:47am
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
January 19th, 2007 at 3:51pm
Great article, Coda.
however, um, I am sort of stuck here:
> Finally, link your mongrel_cluster.yml from your
> app’s config directory to /etc/mongrel_cluster:
how can I create a link to a file that does not exist yet? Isn’t the whole app tree going to be put by capistrano inside a directory named like YYYYMMDDHHMMSS upon deployment (which is the next step in the process)?
So, what should I replace
/your/rails/appwith in the following:sudo ln -s /your/rails/app/config/mongrel_cluster.yml /etc/mongrel_cluster/yourapp.ymlI must be missing something obvious… sorry in advance.
Giuseppe
January 24th, 2007 at 7:18pm
This is a great article and has helped me setup my site, but has anyone else noticed a 15 second proxy timeout when the Mongrel servers are busy or slow? I am using this same setup except I’m using Apache 2.0 and a hardware load balancer instead of mod_proxy_balancer. I’ve tried setting ProxyTimeout and that never works either. I’m just wondering any of you guys have seen this also.
January 27th, 2007 at 7:08pm
you can pass you svn project’s password into cap (and thereby avoid having to do a gratuitous svn co on each server) by adding it to the “checkout” variable.
Heres an example (I use export instead of co) in the deploy.rb file under the OPTIONAL VARIABLES section:
set :checkout, "export --password 'passwordgoeshere'"January 29th, 2007 at 7:04pm
I was inspired to actually create a blog for myself so I could post the instructions for how to host multiple rails apps under a single domain with Apache2.2 and Mongrel. I looked and looked and did not find anyone had written up how to do it so here you go! … It took a while to figure out, but was pretty simple once I understood all the moving parts. That seems to be a common theme in RoR!
http://tonyrose023.blogspot.com/2007/01/multiple-rails-apps-with-mongrel.html
February 4th, 2007 at 10:13am
[...] with Apache 2.0.x. Now, at some point, I realise, I should upgrade to Apache 2.2.x and do the whole Mongrel/mod_proxy_balance thing, or else use lighttpd. But for the moment, I have a slightly exotic Apache config that I [...]
February 9th, 2007 at 2:09pm
Goodbye (notso)fastcgi, Hello Mongrel…
I’ve just started using Mongrel instead of fastcgi for my Rails apps. Its only been a few days but I’m already loving the difference. Its so much faster than before. It wasn’t hard setting up either. Now Apache just proxies requests t…
February 12th, 2007 at 10:20am
[...] “Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You” by Coda Hale [...]
February 12th, 2007 at 4:03pm
Ok got things running with a mix of railsmachine and capistrano and some research.
I saw a previous post where 403 Forbidden errors were popping up. It took me a while of digging and finally found the solution:
for those on Apache2.2 go to the mods-available/ directory under apache2 config. The file is proxy.conf and you will want to change the ‘Deny from all’ line to ‘Allow from all’. Be sure ProxyRequests are off or else I think you become an open proxy for anyone on the internet — which is bad.
I also added the following line to the “check for static” section of the Rewrite rules:
RewriteRule ^/(stylesheets|images|javascripts|favicon.ico) /$1 [QSA]
Not an apache2 guru but this may save someone the hair-pulling I went thru.
One final note: I have configured apache2 so that I can use appname.mydomain.dyndns.org and the railsmachine gem will add an application to my dyndns domain which is very nice (all I need to do is select a different start port, eg 8010, 8020 for each app).
Railsmachine will even configure an /etc/mongrel_cluster/myapp.conf for each set of clusters and a unique id, eg, ‘balancer://myapp1_cluster’, keyword in the apache2 configurarion). I am not too fond of the mydomain/app1 mydomain/app2 paradigm.
No need to purchase a monthly contract with anyone for your own apps - you will need to provide your own fault-tolerance tho.
Thanks for the great info. Been a while (1.3) since I have configured apache and it was a challenge since I knew very little about proxys and load balancing. Also a rails noob but liking it a lot, comming from C++, Perl, Python and living thru PHP programming hell.
February 20th, 2007 at 1:29pm
A problem I ran into: I have a couple of environment variables that were not getting set when the mongrel_cluster was starting thus my pages were not being served correctly.
Solution: I added the environment variables to the /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster
file.
export MYLIB=somelib
They are now being set when the mongrel_cluster service starts.
February 21st, 2007 at 11:25am
To you on a site my calls of son often.I looked satisfied also to me.To me, satisfied, this which he was in you on a site.
disability insurance claims declination letters
March 1st, 2007 at 3:10pm
Richard (154) — I have been noticing timeouts and things too recently on my latest rails project nearbie.com — actually I have been receiving
but it very much feels like a TimeOut issue since the server delays as it is processing an image (resizing a bunch of thumbnails). I tried what this guy was saying but it didnt seem to help either.
http://blog.pomozov.info/posts/apache-mongrel-and-proxy-error.html
Any other thoughts would be greatly appreciated!
Thanks,
Casey
March 2nd, 2007 at 10:21am
[...] that I have developing. I decided on a production environment based on Coda Hale’s “Time For A Grown-Up Server” setup. Fortunately MacPorts (formerly Darwinports) makes it extremely easy to setup Apache 2.2 and [...]
March 8th, 2007 at 1:23am
[...] former is considerably easier to set up. But I followed these instructions to the letter, and many others, and I found that no matter what I did, all of the URLs worked fine within Mongrel and were [...]
March 9th, 2007 at 12:04pm
I’m deploying from a Windows system, and the deployment doesn’t run as root (but as a normal Linux user). However, the chkconfig statements sets the mongrel_cluster to start as root.
So, after server boot, if I use capistrano to update, it cannot touch the mongrel_cluster.
Should I deploy as root? (I don’t like this idea of sending the root password on every deploy).
Otherwise, how do I change the chkconfig of mongrel_cluster to run as my normal user instead of root?
Thanks,
Amir
March 17th, 2007 at 1:45pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
March 19th, 2007 at 12:46pm
[...] I wanted to use Mongrel instead of FastCGI. [...]
March 29th, 2007 at 2:09pm
Hi Coda, thanks once again for the effort.
I got soooo close, but now I seem to be stuck on 403s.
* my apache2.2 (on Ubuntu) also serves non-rails pages, so I set up a separate virtual host for my rails app
* 2 mongrels are properly running on ports 8300 and 8301 (the application runs fine if invoked from the LAN on either port with “address: 127.0.0.1″ commented out in mongrel_cluster.yml)
* I have fixed proxy.conf as koolb suggested on Feb 12
* I have tried the following both in a separate file in conf.d, and inside the relevant vhost, as suggested in RimuHosting Bliki
BalancerMember http://127.0.0.1:8300
BalancerMember http://127.0.0.1:8301
Still, if I try http://myapp.com I get “403 Forbidden” errors, and myapp_errors_log reports the following:
client denied by server configuration: proxy:balancer://mongrel_cluster/
Any clues of what I might be doing wrong? I could provide all relevant config files, but I do not want to clutter this space or abuse your patience… :-)
Cheers,
Giuseppe
March 29th, 2007 at 2:12pm
er, my attempt at marking up my previous post resulted in a bit of code being eaten up. I meant:
BalancerMember http://127.0.0.1:8300
BalancerMember http://127.0.0.1:8301
Thanks again,
Giuseppe
March 30th, 2007 at 3:31pm
Hey Casey (#163). I was seeing the same thing with my install and then found, inexplicably, that it went away when pen was run in the foreground (-f flag).
I added it to my troubleshooting section here:
http://blog.wishlisting.com/?p=20
Hope it helps… and I’m even more hopeful that someone can figure out WHY it helps.
April 4th, 2007 at 3:25pm
If you get 403 errors with corresponding apache log entries of “client denied by server configuration: proxy:balancer://…”, your mod_proxy config is blocking your local balancer config.
On Debian etch (and Ubuntu) look at /etc/apache2/mods-available/proxy.conf:
AddDefaultCharset off
Order deny,allow
Deny from all
#Allow from .example.com
Rather than override that, add this to your Mongrel cluster proxy definition (along with the 127.0.0.1 lines:
Order allow,deny
Allow from all
Problem solved
April 12th, 2007 at 10:28pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You - never had much luck with Pen and co — Apache2’s proxying modules rawk! [...]
April 19th, 2007 at 6:07am
Thank your for this nice article, Coda. I think it help really a lot of user who have to start with Cap’
Could I ask you something happend on my server ?
What’s difference between task :deploy and task :cold_deploy about “restarting” Mongrel ? Because, on my server I have no problem with the restart from task :cold_deploy, but on error occurs with the restart from task :deploy…
As you could see here:
executing task restart
…
executing “cd /var/www/rails… && mongrel_rails cluster::stop”
…
Stopping 3 Mongrel servers…
…/mongrel_rails:162:in `kill’
Operation not permitted
Any idea ?
April 22nd, 2007 at 4:11pm
[...] found Coda Hale’s post on rails mongrel apache and capistrano very [...]
April 24th, 2007 at 12:43am
Hi,
Thanks for the great write-up.
How can I change my rewrite-rules to allow http access to svn on the same server?
April 24th, 2007 at 5:39am
Hey Coda, thanks a lot for your detailed and useful article, it really helped my setting up our new dedicated server for our Rails app.
Thanks!
April 29th, 2007 at 1:34pm
TJC! Thanks for the tip! Much better editing the proxy config there.
I didnt see mention of the use of the railsmachine gem but just about all this apache2 config is set by the railsmachine gem rule:
cap -a setup
cap -a setup_servers
cap -a cold_deploy
BTW, I have a script that takes a default Knoppix 5.1 disc and brings it to a state ready for deployment of your application.
May 3rd, 2007 at 2:54pm
You fokken rule!
This saved my night.
May 4th, 2007 at 9:56am
[...] some more searching and found that Coda Hale has the most elegant solution to the problem. I simplified his solution to the steps below. But before trying anything, you [...]
May 9th, 2007 at 7:04am
Thanks Coda,
Excellent write up on a solid configuration.
May 9th, 2007 at 1:08pm
Re: Setting up SVN on same server.
I use SVN on the same server as my rails demo box (the place where my apps live until payment is received. hehe).
Be sure to create an apache2 config for each host name. sites-available/default should be there already, eg (sites-available/svn,app1,app2) for each host name (all resolving to the same external ip addy).
Put ONE and ONLY ONE NameVirtualHost 192.168.0.10 in ONLY your default host site config file (took me a while to “get” this).
In each other host site config (either a COPY of default or created from the railsmachine: cap -a setup_servers cmd): eg:
sites-available/svn:
ServerName svn.mydomain.com
…
a2ensite svn
May 14th, 2007 at 10:18am
Thanks for an awesome post. It was very helpful. After successful deployment, I’m running into something unexpected.
I’ve mongrel cluster with Apache2 proxy balancer. It seems Apache has cached some content and even if mongrel cluster is shut down, Apache serves up that content. Even when Mongrel cluster is running, still the same STALE content is served.
Any ideas on how this can be resolved?
Thanks
Navneet
May 29th, 2007 at 6:19pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda … talling sendfile, but it doesn’t help–Apache serves the static content, so the 20%-or-so boost on static files is never seen–and it can even cause some pretty severe stability issues. So. No sendfile, and if you’ve got it installed, uninstall it, (tags: rails apache rubyonrails capistrano howto performance) [...]
June 4th, 2007 at 2:24pm
Just to say thank you for this post, its invaluable.
June 8th, 2007 at 6:37am
[...] owe a great deal of thanks to this article posted by codehale on the same topic. The article you are reading here is a summation of [...]
June 20th, 2007 at 2:08pm
I ve got all this cool tutorial through. the only trouble: only a http://myapp.com/ is proxied OK. Any other path supplied after “/” is not proxied. I guess smthing goes wrong with rewrite rules, but no idea what….
June 20th, 2007 at 5:39pm
[...] are you need almost the same configuration as me. As of this writing 1845 people have bookmarked Coda Hale’s excellent guide to setting up Mongrel + Apache on del.icio.us. The article has 187 comments. Why should so many people each have to do the same [...]
June 29th, 2007 at 12:33pm
Getting an error when I try to do the cold deploy - anyone have any ideas what I did wrong?
sudo mongrel_rails cluster::start -C /var/www/spit_your_best_verse/current/config/mongrel_cluster.yml
/usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/lib/mongrel_cluster/init.rb:23:in `merge!’: can’t convert String into Hash (TypeError)
from /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/lib/mongrel_cluster/init.rb:23:in `read_options’
from /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/lib/mongrel_cluster/init.rb:27:in `start’
from /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/lib/mongrel_cluster/init.rb:95:in `run’
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run’
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
from /usr/bin/mongrel_rails:16
June 29th, 2007 at 3:21pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda … mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 3 -c /path/to/your/capistrano/setup’s/current (tags: mongrel rubyonrails apache2) [...]
June 30th, 2007 at 12:22am
[...] Hale write a great piece on best practices for Mongrel / Apache integration and talks about Capistrano (the deployment framework). 0 [...]
July 17th, 2007 at 5:20pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
July 24th, 2007 at 8:00am
Thanks for an excellent tutorial, Coda. A year later it’s still very useful.
I wrote up some instructions for adding Capistrano 2.0 to an existing Apache/Mongrel/Rails mix, if anyone is interested.
July 30th, 2007 at 5:02pm
This has been really useful for me, thanks Coda! For Amazon EC2 users: I have created a public server image that is set up based on this article, for more info see:
http://pauldowman.com/projects/ruby-on-rails-ec2/
August 6th, 2007 at 5:37pm
[...] very thoroughly. Check out Mongrel’s site for more information. I would also recommend this guy’s site, but you’re smart enough to use google, I’m sure you can find your own [...]
August 7th, 2007 at 2:13am
[...] конфигуриране на Mongrel cluster, вижте страхотната статия на Coda Hale. За коректна Debian-базирана инсталация на Rails - вижте [...]
August 17th, 2007 at 9:44pm
[...] 1. http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-y... [...]
August 19th, 2007 at 4:10pm
[...] Time For a Grown-Up Server [...]
August 22nd, 2007 at 2:00am
Thanks for the article, I had some strange problems with apache which I finally solved (with the help of a friend) so I thought I would put the fix here in case anyone else has the same problem.
Upon trying to start Apache I got the error “BalancerMember Can’t find ‘byrequests’ lb method”. It turns out that you have to make sure you load mod_proxy, and mod_proxy_balancer. I only had mod_proxy loaded, which defines the “BalancerMemeber” directive (so I didn’t get Directive Not Found errors”, but doesn’t allow you to use it.
August 22nd, 2007 at 9:29am
It all ran well until cap cold_deploy
cap cold_deploy
the task `cold_deploy’ does not exist
And there isn’t even a cold_deploy.rb in my filesystem.
Same with
cap deploy
the task `deploy’ does not exist
Although I edited the
/var/lib/gems/1.8/gems/capistrano-2.0.0/lib/capistrano/recipes/deploy.rb
cap -T
cap invoke # Invoke a single command on the remote servers.
cap shell # Begin an interactive Capistrano session.
Any Idea?
August 22nd, 2007 at 11:19am
[...] mongrel instances are proxied behind Apache using mod_proxy_balance as described here. This setup works very well and is more and more becoming the defacto standard for deploying Rails [...]
August 22nd, 2007 at 1:50pm
I found out I used capistrano-2.0.0.
I downloaded capistrano-1.4.1.gem from the sourceforge website and installed it after unbinstalling capistrano-2.0.0.
Now cap cold_deploy and cap deploy works.
August 26th, 2007 at 4:53am
Thanks for your great tutorial. I managed to get everything up and running. I had to do some things manually, because I couldn’t get Capistrano 2 work smoothly together with mongrel cluster and I have another problem. I missed something while configuring Apache, because when I browse through my application it won’t show any pictures in the images folder and it won’t link correctly to the stylesheets folder. Do you have any suggestions? Thanks for any help! Greets, Daniel
August 28th, 2007 at 12:16am
Thanks for the tips. It was really easy to work things out. Cheers
August 29th, 2007 at 12:49pm
About the apache.conf:
I think this line has a superfluos ‘/’ in the middle (but works apparently):
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
also, you don’t need the ( and ) on this line, since you’re not referencing the match:
RewriteRule ^/(.*)$ balancer://domain.com_cluster%{REQUEST_URI} [P,QSA,L]
September 3rd, 2007 at 11:00am
[...] to use Apache2 as a kind of Proxy for Mongrel. It turns out that there’s a great one over at CodaHale. So if you’re looking for something like I did, I would really recommend this [...]
September 11th, 2007 at 4:17pm
I’m running into a problem with the Apache2 setup. Every time I try and access the site I receive a “404 Not Found” page. I’m guessing the rewrite rules are not in effect, but have no clue how to make them work properly.
I’m trying to set up redMine in Ubuntu.
Any help is much appreciated!
September 13th, 2007 at 2:48pm
Casey and Richard:
I was having similar issues. Finally figured out that I had to add
Timeout AND ProxyTimeout to the Virtual Host. So:
Timeout xx (seconds)
ProxyTimeout xx (same number of seconds)
September 18th, 2007 at 1:47am
Thanks for this excellent walkthru.
I used it to setup Apache 2.2, Mongrel 1.0.1, Mongrel Cluster 1.0.2,
Rails 1.2.3 on Debian Etch.
I used the following commands to enable all required modules for
apache.
a2enmod rewrite
a2enmod deflate
a2enmod proxy
a2enmod proxy_balancer
a2enmod proxy_http
It took me a while to figure the last one out, although I’ve to admit
that the error message was quite precise:
No protocol handler was valid for the URL /. If you are using a
DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
In addition to the steps mentioned here I had to create two symlinks
to make my system find mongrel’s executables
ln -s /var/lib/gems/1.8/bin/mongrel_cluster_ctl /usr/bin/mongrel_cluster
ln -s /var/lib/gems/1.8/bin/mongrel_rails /usr/bin/
I’m not sure this is the way it’s meant to be, but it worked for me.
I put my app’s config for apache in one file
/etc/apache2/sites-available/myapp and enabled it issuing
a2ensite myapp
Debian users might want to change the location of the logfiles, as
well as the previous mentioned proxy section, adding
Allow from all
to avoid 403 Errors.
On my freshly setup etch I also had to edit
/etc/apache2/sites-available/default changing the asterisks of the
first and second line to the machine's ipaddress, appending the ports
(one NameVirtualHost for each port) due to the following error (I also
did this for myapp):
mixing * ports and non-* ports with a NameVirtualHost address is not
supported, proceeding with undefined results
It now reads like this:
NameVirtualHost xxx.xxx.xxx.xxx:80
NameVirtualHost xxx.xxx.xxx.xxx:8080
<VirtualHost xxx.xxx.xxx.xxx:80>
...
I’m sure I forgot to mention something, sorry for that.
Oh, I changed the setup of the Mongrel Cluster from three to four
workers, because for a dual core machine it just felt right to have a
multiple of two, but I am now pro on that topic. ;)
September 23rd, 2007 at 2:02pm
Looks like my earlier comment didn’t get through…
————-
Thanks for the writeup Coda. Very helpful.
To make the above setup more secure to deny .svn/* requests, add the following rewrite rule to myapp.common
…
# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9
# Don’t allow any .svn accesses
RewriteRule ^(.*/)?\.svn/? - [F,L]
ErrorDocument 403 “Access Forbidden.”
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
…
Of course, you can avoid having .svn directories in the released code by configuring Capistrano to use svn export instead of svn checkout. But I had an older setup that I don’t want to update to the new Capistrano version yet.
Adding
Order allow,deny
Deny from all
didnt’ help since the RewriteEngine was still matching the request and passing it on to the proxy. It took me some time to figure that out, so wanted to throw it out for others.
September 23rd, 2007 at 2:05pm
Messed up the formatting:
The DirectoryMatch code that didn’t work is:
<DirectoryMatch “^.*/\.svn/”>
Order allow,deny
Deny from all
</DirectoryMatch>
September 26th, 2007 at 9:04pm
[...] http://blog.codahale.com/2006/06/19/time-for-a-grown-up-server-rails-mongrel-apache-capistrano-and-y... [...]
September 27th, 2007 at 2:46pm
I am using a Mongrel + Apache 2.2 configuration. It works great, and I am able to rewrite the remote_user header so we dont have a login page (on intranet). Problem is, when using Ajax calls, it any request parameters are lost on repeated, quick requests. If the user waits more than about 5 seconds between requests, the request is fine; less than that, the paramters are lost. This only happens when proxying through Apache. Has anyone else seen this behavior?
October 2nd, 2007 at 6:10pm
Incredibly useful tutorial. Thanks for taking the time to share and teach.
October 4th, 2007 at 7:19am
On the security issue, what if I only want to secure the Rails app? Would the config for SSL change? And what if I wanted to leave a couple of Rails requests (let’s say all that reference a particular controller) open to the world (i.e. search and view), but the rest of the app (DB maintenance) pieces will be secured. How would that change the config?
October 4th, 2007 at 7:20am
I meant to add that the static content would NOT be secured.
October 12th, 2007 at 3:18pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda … (tags: deploy rails mongrel capistrano) [...]
October 27th, 2007 at 12:39pm
update on comments 194
check this out for a rails virtual appliance
http://ec2onrails.rubyforge.org/
October 29th, 2007 at 12:40pm
[...] you’ve read Coda’s motivating post on getting this stack up and running, then some of this will be familiar to you. I’d suggest [...]
October 29th, 2007 at 12:40pm
[...] comes strait from Coda, which came strait from Zed. And you listen to [...]
October 30th, 2007 at 2:31am
Hi and thanks for a great article. I used it as a reference while setting up my system, and everything works great!
BUT; when using Safari 3 on Windows on HTTPS parts of the web which is served by Apache 2.2, images start to randomly disappear. Any ideas on what is happening? This is probably a SSL/Apache issue, but I couldn’t find anything on it anywhere.
November 7th, 2007 at 3:37pm
I’ve never heard about Capistrano before, but now i don’t wanna miss Capistrano.
November 8th, 2007 at 8:06am
[...] blog.codahale.com kpumuk.info Bookmark [...]
November 16th, 2007 at 4:49pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | codablog | Coda Hale More and more Rails developers are finding out that deploying a Rails application isn’t as simple as upload and rename; Rails apps work best when running all the time, and many Rails programmers are moving from traditional, shared hosts, like Dreamhost, to virtual private servers, like Rimuhosting, which allow them full control and responsibility of production servers. [...]
November 27th, 2007 at 7:34pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda … (tags: rubyonrails reference) [...]
December 4th, 2007 at 7:42pm
[...] Lastly, we talked about deployment, and how Charles’ preferred method for deployment is Apache+mongrel. We talked about Capistrano and the way it maintains symlinks to the current svn pulldown for versioning and easy rollback. An excellent article on deploying with apache and mongrel is Coda Hale’s Time for a Grown Up Server. [...]
December 5th, 2007 at 12:16pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda … talk of setting up mongrel clusters (tags: rails hosting) [...]
December 17th, 2007 at 11:56am
[...] hat sich das Ruby-basierte Typo als nicht sehr performant erwiesen. Dies obwohl ich ein Mongrel-Cluster-Setup ausprobiert hatte, dauerte das Rendering der Index-Seite teilweise über 40 Sekunden, wenn das [...]
December 21st, 2007 at 2:05am
Hi,
Thanks for this howto.
I just have a problem with static files (images, css, …), they are rendered very slowly. I have messages like this for every static file in my log :
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (3) applying pattern ‘^/$’ to uri ‘/images/logo.png’
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (3) applying pattern ‘^([^.]+)$’ to uri ‘/images/logo.png’
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (3) applying pattern ‘^/(.*)$’ to uri ‘/images/logo.png’
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (4) RewriteCond: input=’/var/www/rails/myapp/public/images/logo.png’ pattern=’!-f’ => not-matched
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (1) pass through /images/logo.png
Do you have any idea? :(
Thanks in advance!
December 21st, 2007 at 2:05am
Hi,
Thanks for this howto.
I just have a problem with static files (images, css, …), they are rendered very slowly. I have messages like this for every static file in my log :
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (3) applying pattern ‘^/$’ to uri ‘/images/logo.png’[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (3) applying pattern ‘^([^.]+)$’ to uri ‘/images/logo.png’
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (3) applying pattern ‘^/(.*)$’ to uri ‘/images/logo.png’
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (4) RewriteCond: input=’/var/www/rails/myapp/public/images/logo.png’ pattern=’!-f’ => not-matched
[21/Dec/2007:10:58:26 +0100] [myapp.com/sid#800f64c0][rid#80242a80/initial] (1) pass through /images/logo.png
Do you have any idea? :(
Thanks in advance!
January 5th, 2008 at 7:00am
[...] For Rails, there are lots of deployment strategies, some are tuned for compatibility with shared hosting (fastcgi), and some are built for speed and minimum configuration (Litespeed Nginx and Lighttpd), and some are built to leverage the strength and flexibility of stable and established server software (Apache+Mongrel). [...]
January 5th, 2008 at 12:19pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda … (tags: capistrano deployment mongrel rails) [...]
January 5th, 2008 at 7:11pm
The best Tutorial I ever read.
Great Stuff
January 8th, 2008 at 12:07am
[...] Thankfully, the sites I’ve deployed with RoR have caching in place, and essentially amount to a simple static HTML site for Apache to spew out (courtesy of this post). [...]
January 9th, 2008 at 9:52pm
am a newbie to ubuntu. iam totally lame about the concept. so will you kindly tell HOW To starting from apache2.2 and mainly the location of the folders containing the file. my task is to deploy a web server with apache2 with fastcgi & ruby on rails & mongrel & mod_proxy_balancer.
can you pls help me…
January 11th, 2008 at 2:08am
works perfect!! thank you very much!!
January 11th, 2008 at 7:19pm
Very useful post. It helped me a lot.
Thanks!
Maxime
January 13th, 2008 at 5:52am
Hi, can I set up for more applications (domains). If Yes, do U know how? Many thanks!!!
January 16th, 2008 at 1:06am
Thanks for the article. It was helpful, especially the SSL section.
January 16th, 2008 at 11:50pm
I second Ray on the x-javascript issue, My apache debian server has the same issue, it serves out javascript as x-javascript
Also, YSlow recommends adding expire tags which I did in the following way …
ExpiresActive On
ExpiresByType text/css “access plus 1 month”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 month”
ExpiresByType image/png “access plus 1 week”
On another note I noticed this gravatar support is a performance hog, it may make sense to pre-cache images on the server …
January 23rd, 2008 at 3:29am
This tutorial got me most of the way through initial deployment. Thanks for your hard work. Another series of Deployment 101 articles that might be helpful is posted here:
http://jupiterit.com/wordpress/?p=190
I documented all the problems I had with deployment and created a step by step guide for each stage. Hope its helpful.
February 4th, 2008 at 4:34pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda …Walk-through to help you get your Ruby on Rails application up and running as soon as possible. [...]
February 5th, 2008 at 10:08am
to all who get the rrror message
!! Path to log file not valid: log/mongrel.log
In my case it helped when I added the following line to my mongrel_cluster.yml config file:
cwd: /home//current/
hope that helps!
February 7th, 2008 at 1:59am
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You | Archives | codablog | Coda …Walk-through to help you get your Ruby on Rails application up and running as soon as possible. [...]
February 8th, 2008 at 4:15pm
works perfect!! thank you very much!!
February 13th, 2008 at 1:51am
[...] reveal yet more information, including the “pack-of-mongrels” approach which is detailed on Coda Hale’s blog. Thanks to both of these guys for very succinctly laying out solutions and issues on rails [...]
February 20th, 2008 at 1:00pm
[...] you don’t like the trouble caused by dealing with Ruby on Rails on DreamHost, check out this article for some ideas of good [...]
March 2nd, 2008 at 9:09am
[...] rails x apache [...]
March 2nd, 2008 at 4:03pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
March 27th, 2008 at 4:10pm
[...] are already compressed, so re-compression won’t help and might hurt.) If you’re using Coda Hale’s configuration for Apache and Mongrel (and many of us are) the code for compressing text components before download is already in your [...]
March 28th, 2008 at 5:08pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
March 31st, 2008 at 4:38pm
[...] Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You [...]
April 6th, 2008 at 8:08pm
[...] there isn’t much on the subject floating around out there. Problem #2 is what I did find was geared towards Capistrano (another layer of complexity I was hoping to avoid). Problem #3 is this seems to be even [...]
April 7th, 2008 at 9:22pm
[...] [...]
April 23rd, 2008 at 7:07pm
Can you help me with a Ruby question? I’m not sure if it’s Ruby’s fault or Ubuntu’s fault, but I’m getting an error following your directions.
sudo gem install daemons gem_plugin mongrel mongrel_cluster –include-dependencies
Need to update 1 gems from http://gems.rubyforge.org
.
complete
ERROR: While executing gem … (Errno::EROFS)
Read-only file system - /var/lib/gems/1.8/source_cache
Upon subsequent attempts to install daemons or mongrel_cluster, I get the error:
sudo gem install mongrel_cluster –include-dependencies
ERROR: While executing gem … (Errno::EROFS)
Read-only file system - /root/.gem
April 28th, 2008 at 6:01am
[...] see what I mean lets start with what Google suggests. The reverse proxying gets setup something like [...]
May 7th, 2008 at 4:00am
hello friends, iam looking for an answer of my question regarding deploying of ror app on different servers. Question is that : can we deploy our app on different servers without using capistrano? How much work and what type of work have to be done to deploy such app?
i will be thankful to you.
May 8th, 2008 at 2:05am
Hello ,
My previous seminar went well. Now I have an another query, if you help me in this also.
As there is a concept of remoting in .net,
is this possible to deploy the components in ROR and to make these components communicate with each other as done in remoting concept?
Is this possible in ROR?
Please guide me.
Thanks
Harbans
May 24th, 2008 at 8:41am
[...] been a long time advocate of the Apache/Mongrel Rails ever since Coda Hale blessed us with it some time ago, I’ve not since paid a huge amount of attention to the alternative Rails [...]
May 27th, 2008 at 9:33am
[...] this blog post for information on configuring [...]
May 30th, 2008 at 7:39am
[...] on the same server as your mongrel_cluster using a configuration similar to the one outlined here, then request.remote_addr will always be 127.0.0.1, because the request is really coming from your [...]