This post originated from an RSS feed registered with Ruby Buzz
by Robby Russell.
Original Post: Goodbye Pound, Hello Nginx
Feed Title: Robby on Rails
Feed URL: http://feeds.feedburner.com/RobbyOnRails
Feed Description: Ruby on Rails development, consulting, and hosting from the trenches...
I’ve been using pound for several months and it’s been a good relationship. Except, for some strange reason, I noticed that I was getting development mode errors when it was running in production mode. I thought there might be an issue with my mongrel cluster… but that wasn’t the case.
Let me give you a little background to how we’re encouraging customers to handle their deployment on PLANET ARGON.
Most of our hosting customers1 have three tiers (unless you have your own static IP address), one which we manage, two that you manage.
We handle the main web server/proxy server and proxy to your desired load balancer/proxy/server, which is generally any of the following options… depending on your preference.
Well, when a request comes in through Apache, it gets passed off to Pound and each tier has it’s own headers. By the time that it reaches Mongrel, all the requests appear to be coming fromlocalhost.. not the remote address of the person using your application. Notice nothing but localhost requests in your production.log? ...this is the reason.
So, what side-effects does this have? Well, aside from every request looking local… Rails will, by default, output a normal development-mode error message if the request is coming from localhost.
# found in...
# actionpack/lib/action_controller/rescure.rb
# Exception handler called when the performance of an action raises an exception.
def rescue_action(exception)
log_error(exception) if logger
erase_results if performed?
if consider_all_requests_local || local_request?
rescue_action_locally(exception)
else
rescue_action_in_public(exception)
end
end
It seems that this currently causes the exception notification plugin, which we often use, to not work. We noticed this in a staging environment for an application that we’re building for a client about a month ago. After debugging SMTP servers, mongrel configuration… I was baffled.
Nginx to the rescue
After some investigation and attempts to find a workaround in Pound, I decided to redeploy my blog with Nginx. This was a pretty painless process and I was able to use the example posted on the PLANET ARGON Documentation Project.
Nginx allows you to do the following to overwrite the headers being passed to Mongrel.