Ship It! LIVEShip It! LIVE
home about services writing contact

We develop, test, and create fine software products, and design creative solutions to your problems.
The development of software is an intrinsically creative process. We are dedicated to improving our mastery of the art.
Links · RSS Feed
Popular Pages

It's rare to have this much fun reading a book about software. The ideas are smart, relevant, and fundamental. I can be a better programmer today because of the things I read today.
-Joe Fair
...It would be really nice if, as an industry, we could stop being such a bunch of screwed-up clowns and start living up to our potential. Ship It! is one of the things that could help, if only tho...
-Mike Gunderloy
Quoting Watts Humphrey, "Developers are caught in a victim's mentality." We never think it's our fault, it's always somebody else's.
-Jared Richardson

Nginx: My New Web Server (Jun 10)
I recently heard about Nginx. It's a web server with a great track record in Russia that's starting to spread out to the rest of the world. According to a recent podcast I heard, Zed seems to be using it with his production Rails apps, which is always a good sign. At RailsConf I got to eat with Adam Keys and his enthusiasm for it's speed, ease of configuration, and stability caught my attention.

The greatest attraction for me is the ease of configuration. I've wrestled with Apache conf files on and off though the years, but I've never felt like I really "got it". Apache can do nearly anything, but you've got to really invest the time to become an Apache specialist to do anything useful with it. And I never really felt the motivation to become an Apache specialist.

When I set up this web site, I tried to get my Mongrel cluster up and running with Apache but couldn't get it working. So I gave up and dropped back to Pound and Mongrel. Pound load balanced and Mongrel served everything, including the html, Javascripts, CSS, and graphics. A complete reload of the main page took about 30 seconds. Nearly all the time was spent loading graphics, two at a time. And once the browser had the graphics cached, it ran great.

But today I switched to Nginx and a clean reload is taking me 8 seconds. Granted, Mongrel wasn't designed to serve your static content, but wow... that's an improvement!

Here are some Nginx links to get you started.

And here's my configuration file:

worker_processes  2;
events {
    worker_connections  1024;
}
http {
    include       conf/mime.types;
    default_type  application/octet-stream;

    upstream mongrel {
        server 127.0.0.1:7000;
        server 127.0.0.1:7001;
        server 127.0.0.1:7002;    
        server 127.0.0.1:7003;
    }
    log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;
    server {
        listen       80;
        root /usr/local/nginx/html;
        access_log  /usr/local/nginx/logs/access.log  main;
        rewrite_log on;

                location ~ ^/$ {
                  if (-f /index.html){
                    rewrite (.*) /index.html last;
                  }
                   proxy_pass  http://mongrel;
                }

                location / {
                  if (!-f $request_filename.html) {
                    proxy_pass  http://mongrel;
                  }
                                        }

                location ~ .html {
                   root /usr/local/nginx/html;
                }

                  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar
|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
                  root /usr/local/nginx/html;
                }
         }
}

Update: Apparently this call request.host_with_port gets confused when Nginex proxies for Mongrel. If you're reading this via the RSS feed, then you probably noticed that all my URLs were wrong for a few hours. It's fixed now. I should wrap that with a test!

Category: Rails


© 2007 Agile Artisans.