Goodbye Pound, Hello Nginx
11 comments Latest by Sebastian Röbke Sun, 04 Feb 2007 17:08:00 GMT
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.
Each customer has a unique proxy server port and a range of other ports for their mongrel clusters.
So… the typical setup is…
Apache(external:80) [proxies to]==> Pound(localhost:8050) [proxies to]==> Mongrel::Cluster(localhost:10500-10503)
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 from localhost.. 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.
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
Problem Solved!
If there is a workaround for this in Pound, I’d love to be able to relay this information to our customers that haven’t made the switch yet.
Thank you, Brian and Timothy for encouraging me to finally switch my blog to Nginx. ;-)
If you have questions related to deploying Rails applications, be sure to check out the Rails Deployment google group.
1 For more information about our hosting, visit http://planetargon.com/hosting.html.
Enjoying the content? Be sure to subscribe to my RSS feed.




I am sure I could probably just email Planet Argon Support and ask some questions about your setup but since you’ve mentioned each user running their own servers on a range of allocated ports – I thought I’d ask if you were running some sort of VPS setup or doing anything to restrict which ports users can use or is it a standard tried and tested shared-server setup that relies on trust that users’ processes won;t interfere with other users?
Alex,
As far as port usage, it’s a matter of… respect your neighbors. If you’re using a port that is designated for another user and they notify us… we have to stop your process and send you an email asking you to please read the page that explains what your port range is. :-)
In regards to the VPS question, we’re not currently running everything on VPSs, but there is a rumor of a new service coming this month… contact us for more details.
What about file uploads? nginx seems to have a nasty habit of buffering the request before it sends it off to the backend, making upload progress pretty much impossible.
Have you folks made any strides in disabling this?
i’m currently using pound on planet argon and was wondering how i could serve static content in public/ without mongrel. will this give me that ability?
Thanks Robby.
I wasn’t for one moment suggesting you should be offering VPS solutions (although I can see the benefit to some people who don’t want to worry about full dedicated servers). Sounds like you’ll be able to cater for both demand soon enough.
I was more curious if you’d come up with a way to restrict access to port ranges or if, as you put it, you were running a respect your neighbors policy. Nothing wrong with that.
All sounds good.
Alex.
LB…
Yes, the Nginx configuration that is posted on our documentation project will do this for you!
Alex,
We thought about spending the time to restrict port usage, but given all the servers and customers we’ve had… I can count the few instances where we had to kill a process because it was on the wrong port. If I recall, every instance was by accident and was quickly resolved by the offending party. :-)
Kevin,
I haven’t heard about that… will investigate. Thanks for the potential warning!
What’s the point of putting an intermediate proxy between Apache and Mongrel? Why not just use Apache and mod_proxy to proxy to a set of Mongrel processes?
My production Rails app (not at Planet Argon unfortunately) is still running through Apache and Lighttpd. I feel like such an old geezer. I am thinking of deploying new apps on Apache and Mongrel, but what advantage would there be to adding Nginx to the mix?
So many layers, this is starting to feel like J2EE… :-/
Ryan
Ryan,
This is a shared hosting environment, so in order to give our customers the freedom to have more control over their various applications, we proxy everything to one port, which they can pick the technology they want to manage their applications with.
Some customers aren’t using Apache at all as they have a dedicated IP address.
In a dedicated/VPS environment… we don’t encourage the extra tier.
I have an app running on Planet Argon using pound + mongrel (cluster). I’m happy with this vs. lighttd + fastcgi. I wonder if nginx would be better?? hmm …
No one ever “sole” my ports on Planet Argon, and I have always double checked my own config files to make sure I’m not messing up others nor myself. I experienced a few “bad neighbor” episodes on PA where my app slowed to a crawl due to cpu cycle starvation – I believe this is a problem inherit in a shared host arrangement and not a PA issue.
line = ”# actionpack/lib/action_controller/rescure.rb” line.sub(/rescure/, “rescue”) unless rescure.intended?
Thought you should know :)
I ran into the same “localhost” issues with Pound. As I did not want to fix and recompile Pound and Nginx was not an option back then, I used Pen (http://siag.nu/pen/) as a simple replacement (also see: http://mongrel.rubyforge.org/docs/pen_balance.html).