Read my latest article: Announcing RailsDeveloper (posted Wed, 01 Sep 2010 17:01:00 GMT)

Goodbye Pound, Hello Nginx

Posted by Robby Russell Thu, 01 Feb 2007 19:48:00 GMT

29 comments Latest by aaa watches Thu, 02 Sep 2010 05:59: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.

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    Alex Thu, 01 Feb 2007 22:01:29 GMT

    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?

  2. Avatar
    Robby Russell Thu, 01 Feb 2007 22:08:46 GMT

    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.

  3. Avatar
    Kevin Marsh Thu, 01 Feb 2007 22:30:56 GMT

    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?

  4. Avatar
    LB Thu, 01 Feb 2007 23:48:33 GMT

    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?

  5. Avatar
    Alex Fri, 02 Feb 2007 00:44:59 GMT

    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.

  6. Avatar
    Robby Russell Fri, 02 Feb 2007 04:44:06 GMT Recommend me on Working with Rails

    LB…

    was wondering how i could serve static content in public/ without mongrel.

    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!

  7. Avatar
    Ryan Fri, 02 Feb 2007 09:33:50 GMT

    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

  8. Avatar
    Robby Russell Fri, 02 Feb 2007 14:04:33 GMT Recommend me on Working with Rails

    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.

  9. Avatar
    dagny Fri, 02 Feb 2007 18:11:56 GMT

    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.

  10. Avatar
    Hank Fri, 02 Feb 2007 19:29:38 GMT

    line = ”# actionpack/lib/action_controller/rescure.rb” line.sub(/rescure/, “rescue”) unless rescure.intended?

    Thought you should know :)

  11. Avatar
    Sebastian Röbke Sun, 04 Feb 2007 17:08:00 GMT

    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).

  12. Avatar
    Bob Fri, 19 Jun 2009 10:47:49 GMT

    solution for all “localhost” logs on apache backend from pound:

    http://stderr.net/apache/rpaf/

  13. Avatar
    wholesale laptop battery Thu, 13 May 2010 06:49:58 GMT

    which is generally any of the following options… depending on your preference.

  14. Avatar
    nike lebron Mon, 24 May 2010 04:20:12 GMT
    nike lebron, nike lebron
  15. Avatar
    nike lebron Mon, 24 May 2010 04:20:35 GMT
    nike lebron, nike lebron
  16. Avatar
    YYY Sat, 29 May 2010 01:37:58 GMT
  17. Avatar
    Air Yeezy Jordan VI Sat, 12 Jun 2010 05:47:33 GMT

    ert er

  18. Avatar
    chanel h0684 Sat, 12 Jun 2010 05:47:49 GMT

    re

  19. Avatar
    mbt walk blue Thu, 17 Jun 2010 01:01:02 GMT

    colorful supra muska skytop

  20. Avatar
    colorful supra muska skytop Thu, 17 Jun 2010 01:01:08 GMT

    colorful supra muska skytop

  21. Avatar
    lebron soldier iii Thu, 17 Jun 2010 03:00:04 GMT

    yui

  22. Avatar
    black patent supra strapped ns Sun, 20 Jun 2010 02:44:44 GMT

    mbt chapa ebony

  23. Avatar
    lida daidaihua Tue, 29 Jun 2010 04:56:27 GMT

    Many may imitate the Tiffany jewellery styling, but some manufacturers actually are true. Take some time to think about what a simple Tiffany necklaces in the form of a desk lamp can do for you. A decorative stained glass lighting fixture from silver necklaces will add charm and warmth to any setting. Tiffany pendants and other luxury brands have long argued that counterfeit merchandise bearing their names are sold on eBay. These effective lida daidaihua do not have any harmful side-effects. You get great discounts on your box of daidaihua , the entire details and instructions to take these effective lida slimming is clearly mentioned on the site, slimming capsule that are easily available on the online stores. slimming capsules are mostly safe and able but several affected and abortive articles actualize a bad name for all slimming capsule .

  24. Avatar
    Monogram Dentelle Mon, 19 Jul 2010 17:12:31 GMT

    Louis Vuitton Speedy 30 Golden M95397 Louis Vuitton Speedy 30 Golden Louis Vuitton Speedy 30 Silver M95398 Louis Vuitton Speedy 30 Silver Louis Vuitton Batignolles Horizontal M95399 Louis Vuitton Batignolles Horizontal Louis Vuitton Batignolles Horizontal Silver M95400 Louis Vuitton Batignolles Horizontal Silver

  25. Avatar
    http://www.fashioniphone.com/iphone-cases Tue, 03 Aug 2010 08:59:17 GMT
  26. Avatar
    SPEEDY 35 Thu, 05 Aug 2010 17:39:19 GMT

    so good

  27. Avatar
    waist bag factory Mon, 09 Aug 2010 03:30:01 GMT

    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 runnin

  28. Avatar
    xubeibei Mon, 09 Aug 2010 06:48:36 GMT

    Nginx seems to have a nasty habit of buffering the request before it sends it off to the backend. jewelry bracelets

  29. Avatar
    aaa watches Thu, 02 Sep 2010 05:59:00 GMT

Share your thoughts... (really...I want to hear them)

Comments