Received an en email today from Cody K on my use of Webrick in production for Lean Domain Search:
Hey Matt,
Lean Domain Search is really neat – thanks for making it available.
Just wanted to let you know that it’s a really bad idea to run Ruby web apps with Webrick in production – you should be using something like nginx and either Unicorn or Passenger. Those are battle-hardened and production-ready, whereas Webrick’s sole purpose is for development environments, and, as such, is not heavily tested (if at all) for security issues and whatnot.
Just a friendly heads up. :) Thanks again.
Heroku’s Rails 3 docs are also pretty clear on this and I remember reading it during my initial upgrade, but never got around to actually doing it.
Thin is a recommended app server over Webrick (the default for rails).
Switching to Thin is pretty easy:
1. Add gem 'thin'
to your Gemfile:
I added it to the production group because I want to keep using Webrick in development for now.
2. Make sure that you run bundle install
to update your Gemfile otherwise you’ll receive a warning like this when you push to Heroku:
You are trying to install in deployment mode after changing your Gemfile. Run `bundle install` elsewhere and add the updated Gemfile.lock to version control. You have added to the Gemfile: * thin
3. Add a Procfile to your root directory to instruct Heroku to use Thin instead of Webrick:
4. Commit and push your updated app to Heroku.
If all went well, you should see something like this in your logs:
2012-01-18T12:44:33+00:00 app[web.1]: >> Using rack adapter
2012-01-18T12:44:33+00:00 app[web.1]: >> Thin web server (v1.3.1 codename Triple Espresso)
2012-01-18T12:44:33+00:00 app[web.1]: >> Listening on 0.0.0.0:38951, CTRL+C to stop
2012-01-18T12:44:33+00:00 app[web.1]: >> Maximum connections set to 1024
2012-01-18T12:44:34+00:00 heroku[web.1]: State changed from starting to up
Too easy.
One thing confused me though: How did Cody know that I was using Webrick? I emailed him and asked.
His response:
I mistakenly typed some bogus characters in at the end of my address bar while I was on your site…something like this: http://www.leandomainsearch.com/search?q=up^jf
Sure enough, Webrick fails loudly when the URL includes a caret:
Touché.
Question I have is – why is Heroku using Webrick by default? It uses Postgres by default (as opposed to Sqlite) why not a production ready web-server?
So I just spent like an hour searching for a way to switch from WeBrick to Thin – (WeBrick complained about the long search URL’s I had.) This is by far the most clear, concise explanation I found. Thanks!
OK, but how do you run Thin for a simple Ruby app, without Rails? What is $RACK_ENV? How do you run it in development?