<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>nginx &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/nginx/</link>
	<description>Feed of posts on WordPress.com tagged "nginx"</description>
	<pubDate>Thu, 21 Aug 2008 13:10:42 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[stuff I would have wanted to see at WordCamp SF 2008]]></title>
<link>http://ckon.wordpress.com/?p=226</link>
<pubDate>Sun, 17 Aug 2008 05:52:13 +0000</pubDate>
<dc:creator>_ck_</dc:creator>
<guid>http://ckon.wordpress.com/?p=226</guid>
<description><![CDATA[Apparently they crammed it all into one day this year and the tech stuff was held separately (downst]]></description>
<content:encoded><![CDATA[<p>Apparently they crammed it all into one day this year and the tech stuff was held separately (downstairs) from the general stuff (don't want those devs and general users to mingle, ruh roh!)</p>
<p>I don't fly so I was hoping for some audio or video recordings. I found a live video feed from some bloggers upstairs but nothing downstairs (at least not that I could find).  I need to hunt down the slideshows for Crazyhorse, <a href="http://apeatling.wordpress.com/2008/08/16/buddypress-slides-links-from-wordcamp-sf-2008/">BuddyPress</a>, Nginx etc. Finding a schedule of the tech stuff would probably be a good start, I found one for the <a href="http://smbrown.wordpress.com/2008/08/16/sf-2008-wordcamp-schedule/">general stuff upstairs</a> but not downstairs. ZDnet covered only the non-dev side, <a href="http://blogs.zdnet.com/weblife/?p=143">but in detail</a>.</p>
<p>Was there *no* bbPress presentation this year at WordCamp? Really?<br />
<a href="http://search.twitter.com/search?q=&#38;ands=wordcamp&#38;phrase=&#38;ors=&#38;nots=&#38;tag=&#38;lang=all&#38;from=&#38;to=&#38;ref=&#38;near=&#38;within=15&#38;units=mi&#38;since=2008-08-15&#38;until=2008-08-18&#38;rpp=50">Twitter went insane with WordCamp stuff!</a><br />
added: some really good <a href="http://www.jeremyperson.com/?p=2228&#38;print=1">notes from Jeremy Person</a><br />
<!--more--><br />
ps. I can't believe Matt stopped using LiteSpeed and switched to Nginx. As fast as Nginx is, LiteSpeed is still faster and definitely has a better interface and tech support, but I guess Matt can afford his own techs now to support open source stuff so it makes him feel better to have that flexibility. LiteSpeed isn't cheap, especially when you have as many servers as Automattic must have.</p>
<p>pps. I can't believe Matt didn't think of all the vegans in SF and only had a BBQ lunch </p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[SliceHost]]></title>
<link>http://pvillega.wordpress.com/2008/08/16/slicehost/</link>
<pubDate>Sat, 16 Aug 2008 15:56:43 +0000</pubDate>
<dc:creator>Pere Villega</dc:creator>
<guid>http://pvillega.wordpress.com/2008/08/16/slicehost/</guid>
<description><![CDATA[Por fin he encontrado lo que buscaba: Slicehost. Servicio de hosting en que tienes acceso vía ssh c]]></description>
<content:encoded><![CDATA[<p>Por fin he encontrado lo que buscaba: <a target="_blank" href="http://www.slicehost.com/">Slicehost</a>. Servicio de hosting en que tienes acceso vía ssh como root a tu servidor, para instalar lo que quieras. Y a un precio asequible (20$ la versión de 256Mb de ram). Suficiente para almacenar tu blog y alguna otra aplicación. Servicio de backup y una wiki completa con muchos artículos interesantes. Una muestra de lo que se peude conseguir mediante virtualización y una buena arquitectura en el datacenter.</p>
<p>De hecho, he encontrado este <a target="_blank" href="http://www.mensk.com/webmaster-toolbox/perfect-ubuntu-hardy-nginx-mysql5-php5-wordpress/">manual sobre como instalar Wordpress</a> (usando <a target="_blank" href="http://nginx.net/">nginx</a>, una versión ligera de Apache muy eficiente) en Slicehost, incluyendo los pasos para hacer tu servidor más seguro. Una pequeña joya.</p>
<p>Como bonus he descubierto "<a target="_blank" href="http://just-ping.com/i">Just-ping</a>", una web para hacer pings desde varios servidores alrededor del mundo a tu web, viendo tiempos de respuesta. Y con un enlace a "<a target="_blank" href="http://www.just-traceroute.com/?utm_source=just-ping.com&#38;utm_medium=site&#38;utm_campaign=just-ping">just-traceroute</a>" para ver los caminos que recorre la comunicación.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Django / Nginx -- Making SSL Work on Django Behind a Reverse Proxy &amp; HTTP Only Apache]]></title>
<link>http://yuji.wordpress.com/?p=106</link>
<pubDate>Fri, 15 Aug 2008 19:02:38 +0000</pubDate>
<dc:creator>Yuji</dc:creator>
<guid>http://yuji.wordpress.com/?p=106</guid>
<description><![CDATA[How to make SSL work on Django when the certification is done on the front-end server &amp; apache i]]></description>
<content:encoded><![CDATA[<p>How to make SSL work on Django when the certification is done on the front-end server &#38; apache is only listening on http.</p>
<p>I have nginx working as a reverse proxy for Apache / mod_python serving Django, somewhat according to the instructions here:</p>
<p><a href="http://lethain.com/entry/2007/jul/17/dreamier-dream-server-nginx/">http://lethain.com/entry/2007/jul/17/dreamier-dream-server-nginx/</a></p>
<p>Basically, Nginx sits in the front, and forwards all requests but /media/ to apache.</p>
<p>My problem arose when I wanted to implement this SSL Redirect middleware: <a href="http://www.djangosnippets.org/snippets/880/">http://www.djangosnippets.org/snippets/880/</a></p>
<p>Last time I set up SSL on Django, I had nginx forward HTTPS requests to a separate apache virtual host, also listening on port 443. The SSL certification was on apache, so Djangos request.is_secure() returned True with no problems.</p>
<p>This time though, I have nginx dealing with the SSL, and forwarding the request to the same apache as regular http (one apache vhost), so apache is blissfully unaware of ssl. This means request.is_secure() always returns false, which means the SSLRedirect middleware endlessly loops around a redirect. Endlessly redirecting because is_secure() always returns False.</p>
<p>To fix the problem I just set up my nginx to add a header "HTTP_X_FORWARDED_PROTOCOL" = "https"</p>
<p>and replaced the request.is_secure() in our SSLRedirect middleware with a check to first see if the above mentioned header is in request.META, and then if its value is 'https'. Return true if that is the case, and we successfully get a redirect.</p>
<p>I guess the value of it doesn't matter, just that it exists vs not, but that feels very dirty.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Private Downloads with attachment_fu and nginx]]></title>
<link>http://enleitened.wordpress.com/?p=173</link>
<pubDate>Fri, 15 Aug 2008 08:31:13 +0000</pubDate>
<dc:creator>Eric Hedberg</dc:creator>
<guid>http://enleitened.wordpress.com/?p=173</guid>
<description><![CDATA[So, you&#8217;re using attachment_fu to handle user file uploads in your rails app, right?  If you]]></description>
<content:encoded><![CDATA[<p>So, you're using <a href="http://clarkware.com/cgi/blosxom/2007/02/24#FileUploadFu">attachment_fu</a> to handle user file uploads in your rails app, right?  If you're also using <a href="http://nginx.net/">Nginx</a> for your web server, here's a quick and dirty way to do controlled file access in less than 10 lines of code.</p>
<p><!--more-->Now, the documentation for attachment_fu indicates that the standard way to do downloads using the file system store is Attachment#public_filename.  That works great, if you're comfortable with relying on somewhat obfuscated URLs for privacy, and nothing else.  You can always do something like this in your view:<br />
[sourcecode language='ruby']<br />
<%= link_to @attachment.filename, @attachment.public_filename -%><br />
[/sourcecode]</p>
<p>So how do we add some access control to this?  Let's start with your AttachmentsController, and add a #show action.</p>
<p>[sourcecode language='ruby']<br />
def show<br />
  @attachment = current_user.attachments.find(params[:id])<br />
  # Do some other stuff if we need to<br />
  head(:x_accel_redirect => @attachment.public_filename,<br />
       :content_type => @attachment.content_type,<br />
       :content_disposition => "attachment; filename=\"#{@attachment.filename}\"")<br />
end<br />
[/sourcecode]</p>
<p>The X-Accel-Redirect header tells nginx to serve up the assigned path directly, letting Mongrel get on to serving the next request.</p>
<p>Now, in your nginx.conf, you need to configure your attachments path, which should work something like this (inside your main server section).</p>
<p>[sourcecode language='jscript']<br />
location /attachments {<br />
  root /var/www/myapp/public;<br />
  internal;<br />
}<br />
[/sourcecode]</p>
<p>You'll want to replace the root directive with the actual path to RAILS_ROOT/public.  The internal keyword tells nginx that it should only serve up files under that location when directed to via X-Accel-Redirect.</p>
<p>Hope this helps.</p>
<p>Spread it: <a href="http://del.icio.us/post?url=http://enleitened.wordpress.com/2008/08/15/private-downloads-with-attachment_fu-and-nginx/;title=Private+Downloads+With+Attachment_fu+and+Nginx"><img src="http://sunburntkamel.wordpress.com/files/2006/11/delicious.gif" alt="add to del.icio.us" /></a>&#124;<a href="http://digg.com/submit?phase=2&#38;url=http://enleitened.wordpress.com/2008/08/15/private-downloads-with-attachment_fu-and-nginx/"><img src="http://sunburntkamel.wordpress.com/files/2006/11/digg.gif" alt="Digg it" /></a>&#124;<a href="http://ma.gnolia.com/bookmarklet/add?url=http://enleitened.wordpress.com/2008/08/15/private-downloads-with-attachment_fu-and-nginx/;title=Private+Downloads+With+Attachment_fu+and+Nginx"><img src="http://sunburntkamel.wordpress.com/files/2006/11/magnolia.gif" alt="add to ma.gnolia" /></a>&#124;<a href="http://www.stumbleupon.com/submit?url=http://enleitened.wordpress.com/2008/08/15/private-downloads-with-attachment_fu-and-nginx/&#38;title=Private+Downloads+With+Attachment_fu+and+Nginx"><img src="http://sunburntkamel.wordpress.com/files/2006/11/stumbleit.gif" alt="Stumble It!" /></a>&#124;<a href="http://reddit.com/submit?url=http://enleitened.wordpress.com/2008/08/15/private-downloads-with-attachment_fu-and-nginx/;title=Private+Downloads+With+Attachment_fu+and+Nginx"><img src="http://sunburntkamel.wordpress.com/files/2006/11/reddit.gif" /></a>&#124;<a href="http://www.facebook.com/sharer.php?u=http://enleitened.wordpress.com/2008/08/15/private-downloads-with-attachment_fu-and-nginx/&#38;t=Private+Downloads+With+Attachment_fu+and+Nginx"><img src="http://sunburntkamel.wordpress.com/files/2008/02/facebookcom.gif" alt="post to facebook" /></a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Install Nginx webserver on Ubuntu Hardy]]></title>
<link>http://blogabooga.wordpress.com/?p=41</link>
<pubDate>Thu, 07 Aug 2008 03:07:54 +0000</pubDate>
<dc:creator>blogabooga</dc:creator>
<guid>http://blogabooga.wordpress.com/?p=41</guid>
<description><![CDATA[Nginx (pronounced &#8220;engine x&#8221;) is a free, open-source, high-performance HTTP server and r]]></description>
<content:encoded><![CDATA[<p>Nginx (pronounced "engine x") is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Written by Igor Sysoev in 2005, Nginx now hosts between 1% and 4% of all domains worldwide. Although still in beta, Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption.</p>
<p><strong>Basic HTTP features:</strong></p>
<ol>
<li>Handling of static files, index files, and autoindexing; open file descriptor cache;</li>
<li>Accelerated reverse proxying without caching; simple load balancing and fault tolerance;</li>
<li>Accelerated support without caching of remote FastCGI servers; simple load balancing and fault tolerance;</li>
<li>Modular architecture. Filters include gzipping, byte ranges, chunked responses, XSLT, and SSI. Multiple SSI inclusions within a single page can be processed in parallel if they are handled by FastCGI or proxied servers.</li>
<li>SSL and TLS SNI support.</li>
</ol>
<p><strong>How to install Nginx</strong></p>
<p><code>sudo aptitude install nginx</code></p>
<p><strong>How to start Nginx</strong></p>
<p><code>sudo /etc/init.d/nginx start</code></p>
<p><strong>Testing Nginx</strong></p>
<p><a href="http://localhost/">http://localhost/</a></p>
[caption id="attachment_42" align="aligncenter" width="300" caption="Testing nginx web server"]<a href="http://blogabooga.wordpress.com/files/2008/08/screenshot-welcome-to-nginx-mozilla-firefox.png"><img class="size-medium wp-image-42" src="http://blogabooga.wordpress.com/files/2008/08/screenshot-welcome-to-nginx-mozilla-firefox.png?w=300" alt="Testing nginx web server" width="300" height="174" /></a>[/caption]
<p><strong>Start and Stop nginx webserver</strong></p>
<p>Following are the commands to start, stop and restart nginx</p>
<p><strong>Start</strong><br />
<code>sudo /etc/init.d/nginx start</code></p>
<p><strong>Stop</strong><br />
<code>sudo /etc/init.d/nginx stop</code></p>
<p><strong>Restart</strong><br />
<code>sudo /etc/init.d/nginx restart</code></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Django FastCGI init.d How To]]></title>
<link>http://jgeewax.wordpress.com/?p=32</link>
<pubDate>Mon, 28 Jul 2008 19:49:48 +0000</pubDate>
<dc:creator>JJG</dc:creator>
<guid>http://jgeewax.wordpress.com/?p=32</guid>
<description><![CDATA[Lately I&#8217;ve been working a lot with the Django web framework and while there are tons of resou]]></description>
<content:encoded><![CDATA[<p>Lately I've been working a lot with the <a href="http://www.djangoproject.com" target="_blank">Django web framework</a> and while there are tons of resources for Django itself, the process of getting a full stack up and running on a remote server is not as well documented so I figured I'd share one of the challenges I just finished dealing with.</p>
<p>I have a VPS that hosts my Django application via FastCGI behind nginx on Ubuntu 7.10. Nginx comes with an init.d script which starts it at boot time (for me on Ubuntu it runs as /etc/rc5.d/S20nginx -&#62; /etc/init.d/nginx) but I was having to turn the Django app on (via FastCGI) every time the server was rebooted. Since the only reason nginx runs was for my Django app, I wanted the app to start up just like nginx does so that on a reboot, server crash, etc I don't need to ssh in and restart the app. To do this, I started with the posting on the Django wiki (<a href="http://code.djangoproject.com/wiki/InitdScriptForLinux" target="_blank">http://code.djangoproject.com/wiki/InitdScriptForLinux</a>), and then tweaked it for my own purposes, mainly: one single Django app.</p>
<p>The idea here is that I'd simply run `/etc/init.d/my_django_app start` and be done with it while the server itself would do this automatically when it boots up. Here is what I did to let me do this.</p>
<ol>
<li>Tweaked the init.d script, you can find it here:<br />
<a href="http://static.geewax.org/my_django_app" target="_blank">http://static.geewax.org/my_django_app</a></li>
<li>Copied that script into `/etc/init.d/my_django_app`</li>
<li>Ran `update-rc.d my_django_app defaults`</li>
<li>Rebooted the machine to test it out</li>
</ol>
<p>Note that the update-rc.d (I'm told) is only for Ubuntu (or Debian-like) systems.</p>
<p>Now, if I wanted to run more than one app, I can copy the script to a different name and follow the procedure again which lets me do fine-grained application enabling/disabling of Django services should the need arise.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Hosting your Website on S3]]></title>
<link>http://jgeewax.wordpress.com/?p=17</link>
<pubDate>Sun, 27 Jul 2008 18:45:06 +0000</pubDate>
<dc:creator>JJG</dc:creator>
<guid>http://jgeewax.wordpress.com/?p=17</guid>
<description><![CDATA[I was having trouble figuring out how to offload most of the bandwidth of a static website, and whil]]></description>
<content:encoded><![CDATA[<p>I was having trouble figuring out how to offload most of the bandwidth of a static website, and while I have a personal VPS server (which runs a full xen instance, and is very nice, check out <a href="http://www.vpslink.com" target="_blank">http://www.vpslink.com</a>), I just didn't want the traffic going through this tiny server, having it serve up tons of images, etc.</p>
<p>There was also the possibility that the static website (for whatever reason) could start getting hammered with requests, and this tiny xen instance would definitely not scale very well. (And we all know how scalability is the best thing since bubble gum...)</p>
<p>To deal with this situation, I sat down and started brainstorming on how to let Amazon and S3 handle my static web hosting and here is my result:</p>
<p>There are three components here: DNS entries (I use bind9) , a web server (I use nginx), and of course, S3.</p>
<p><strong>Web Server (nginx):</strong></p>
<p>I decided that I wanted people to be able to go to http://example.org and http://www.example.org (and have http://example.org redirect to the www subdomain). Unfortunately S3 doesn't support a default index page (that is, 'bucket.s3.amazonaws.com/' returns the XML of a list result rather than showing the contents of index.html), so I need to do some rewriting:</p>
<ol>
<li>Rewrite the non-www address to the www address;</li>
<li>Rewrite the root get request (/) to index.html; and</li>
<li>Rewrite all requests to a www1 subdomain which would handle the static data.</li>
</ol>
<p>My nginx.conf and sites-enabled/example.org files are here:</p>
<ul>
<li><a href="http://static.geewax.org/nginx.conf" target="_blank">http://static.geewax.org/nginx.conf</a></li>
<li><a href="http://static.geewax.org/sites-enabled.example.org" target="_blank">http://static.geewax.org/sites-enabled.example.org</a></li>
</ul>
<p><strong>DNS Entries (bind9):</strong></p>
<p>Note: Although I use bind because I have a full xen instance, you could easily just set your zone file to have these similar records.</p>
<p>We want to be able to handle the root, and the www subdomain, and send off the www1 (static) subdomain onto s3 to do the actual hosting. This translates into the following records:</p>
<p>(This assumes your root A record points to 1.2.3.4)<br />
www IN A 1.2.3.4 # (IP address of your server)<br />
www1 IN CNAME s3.amazonaws.com. # (Note the trailing dot)</p>
<p>My zones/example.org.db file is here: <a href="http://static.geewax.org/example.org.db" target="_blank">http://static.geewax.org/example.org.db</a></p>
<p><strong>S3:</strong></p>
<p>In your S3 console (I use the S3 Organizer Firefox plugin) you should create a bucket called www1.example.org (this gives you the URL www1.example.org.s3.amazonaws.com). The CNAME you created in the DNS records will point to S3 and this bucket will be accessed for data. Now all you have to do is upload your content to S3 and you're all set.</p>
<p><strong>Issues:</strong></p>
<p>Obviously the main issue here is that the first hit to the website will go through my server, but afterwards all data is strictly sticking to S3; I think I can live with a first hit penalty of a couple rewrites in nginx.</p>
<p><strong>References:</strong></p>
<ol>
<li><a href="http://wiki.codemongers.com/NginxHttpRewriteModule" target="_blank">http://wiki.codemongers.com/NginxHttpRewriteModule</a></li>
</ol>
]]></content:encoded>
</item>
<item>
<title><![CDATA[nginx + mongrel installation and configuration for RoR app.]]></title>
<link>http://linxfo.wordpress.com/?p=22</link>
<pubDate>Wed, 23 Jul 2008 04:15:35 +0000</pubDate>
<dc:creator>linxfo</dc:creator>
<guid>http://linxfo.wordpress.com/?p=22</guid>
<description><![CDATA[
I&#8217;m going to compile in nginx server from the source. I&#8217;m assuming that you&#8217;ve pa]]></description>
<content:encoded><![CDATA[<div class="entry-content">
<p>I'm going to compile in nginx server from the source. I'm assuming that you've packages like ruby, Rails etc. pre-installed on your system/server.</p>
<p>I've compiled in nginx from the source, so you'll need a gcc complier.</p>
<pre>Download the source.
wget http://sysoev.ru/nginx/nginx-0.5.35.tar.gz

Untar it
tar zxvf nginx-0.5.35.tar.gz

Run.

cd nginx-0.5.35
./configure --prefix=/usr/local/nginx
make
make install</pre>
<p>If everything does fine, nginx will get installed /usr/local/nginx</p>
<p>Here is a sample nginx configuration file. Just copy it as nginx.conf(/usr/local/nginx/conf/nginx.conf) and modify it accordingly four your application setup.</p>
<pre>user  www www;
worker_processes  3;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /usr/local/nginx/conf/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] $status '
                      '"$request" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;

        gzip  on;
    upstream mongrel {
     server 127.0.0.1:4000;
     server 127.0.0.1:4001;
    }

        #Rails App here
            server {
        listen       80;
        root /var/www/railsapp/public;
        index index.html index.htm;
        server_name yourdomain.com www.yourdomain.com;
        client_max_body_size 50M;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
         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;
         proxy_redirect false;
         proxy_max_temp_file_size 0;

         if (-f $request_filename) {
            break;
          }
         if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
         }
         if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
         }
         if (!-f $request_filename) {
            proxy_pass http://mongrel;
            break;
         }

        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /500.html;
        location = /500.html {
            root  /var/www/railsapp/public;
        }
    }

}</pre>
<p>You may start the nginx server using the command</p>
<pre>/usr/local/nginx/bin/nginx -c /usr/local/nginx/conf/nginx.conf</pre>
<p>Now you may want an init startup script to start&#124;stop&#124;restart the server. Just copy the below script as /etc/init.d/nginx and set it executable(chmod 755 /etc/init.d/nginx)</p>
<pre>#!/bin/sh

# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author:       Ryan Norbauer
# Modified:     Geoffrey Grosenbach http://topfunky.com

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON &#124;&#124; exit 0

d_start() {
  $DAEMON -c $CONFIGFILE &#124;&#124; echo -n " already running"
}

d_stop() {
  kill -QUIT `cat $PIDFILE` &#124;&#124; echo -n " not running"
}

d_reload() {
  kill -HUP `cat $PIDFILE` &#124;&#124; echo -n " can't reload"
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
  reload)
        echo -n "Reloading $DESC configuration..."
        d_reload
        echo "reloaded."
  ;;
  restart)
        echo -n "Restarting $DESC: $NAME"
        d_stop
        # One second might not be time enough for a daemon to stop,
        # if this happens, d_start will fail (and dpkg will break if
        # the package is being upgraded). Change the timeout if needed
        # be, or change d_stop to have start-stop-daemon use --retry.
        # Notice that using --retry slows down the shutdown process somewhat.
        sleep 1
        d_start
        echo "."
        ;;
  *)
          echo "Usage: $SCRIPTNAME {start&#124;stop&#124;restart&#124;force-reload}" &#62;&#38;2
          exit 3
        ;;
esac

exit 0</pre>
<p>Also don't forget to add the user www using "useradd -s /sbin/nologin www" if the user doesn't exists.</p>
<p>Now time to setup mongrel for your app. Install the mongrel gem, if it's not installed already.</p>
<pre>gem install mongrel</pre>
<p>Then configure the mongrel cluster for your app and start the mongrel server.</p>
<pre>cd /var/www/railsapp (your application directory)

mongrel_rails cluster::configure -e production -p 4000 -N 2

mongrel_rails cluster::start</pre>
<p>You can of course use the mongrel_rails cluster::start&#124;stop&#124;restart commands to manage your mongrel instance.</p>
<p>Hope that this tutorial is useful...</p></div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Soporte de Syslog para Nginx]]></title>
<link>http://lbosque.wordpress.com/?p=95</link>
<pubDate>Thu, 10 Jul 2008 09:06:08 +0000</pubDate>
<dc:creator>Luis</dc:creator>
<guid>http://lbosque.wordpress.com/?p=95</guid>
<description><![CDATA[Estos días tenía la necesidad de hacer que nginx mandase sus logs al syslog local.
Nginx no tiene ]]></description>
<content:encoded><![CDATA[<p>Estos días tenía la necesidad de hacer que <a href="http://nginx.net/">nginx</a> mandase sus logs al syslog local.<br />
Nginx no tiene soporte nativo para usar syslog. Puede escribir los logs o en fichero o mandarlos a un pipe.<br />
Estuve bsucando y encontré un <a href="http://bugs.gentoo.org/show_bug.cgi?id=222373">parche</a> de la versión 0.6.31 que resuelve el problema. <a href="http://www.ruby-forum.com/topic/153141">Aquí</a> habla también un poco del parche.</p>
<p>A pesar de que en ese último link explica por encima como hacerlo, lo voy a contar yo también.</p>
<ul>
<li>Bajamos la versión 0.6.31 de nginx en <a href="http://sysoev.ru/nginx/nginx-0.6.31.tar.gz">http://sysoev.ru/nginx/nginx-0.6.31.tar.gz</a>. Según el comentario de Marlon (el creador del parche) debería funcionar también con las versiones 0.6.30 y 0.6.29, y mirando los changelogs pienso que tambíen debería funcionar en la última que es la 0.6.32. Si alguien lo prueba que me lo diga.</li>
<li>Descomprimimos:<br />
<code># cd /usr/src/<br />
# tar xvzf nginx-0.6.31.tar.gz</code></li>
<li>Bajamos el parche:<br />
<code># wget http://bugs.gentoo.org/attachment.cgi?id=153345 -O nginx_syslog.patch</code></li>
<li>Parcheamos:<br />
<code># patch -p0 &#60; nginx_syslog.patch</code>
</li>
<li>Compilamos e instalamos nginx:<br />
<code># cd nginx-0.6.31<br />
# ./configure --with-syslog<br />
# make<br />
# make install</code></li>
</ul>
<p>En mi caso antes de compilar he tenido que hacer un cambio en una linea de los fuentes del nginx. He tenido que substituir en el fichero <em>auto/cc/gcc</em> la siguiente linea:<br />
<code>CFLAGS="$CFLAGS -Werror"</code><br />
por:<br />
<code>CFLAGS="$CFLAGS"</code></p>
<p>Esto únicamente hace que no se rompa la compilación al encontrar algun warning. En mi caso los warning que lanza la compilación se pueden ignorar tranquilamente, por lo que resulta seguro continuar con ellos.</p>
<p>Si todo ha ido bien deberíamos de tener funcionando nginx. Faltaría unicamente configurarlo y ponerlo en marcha. En el fichero de configuración no hace falta indicar nada para que mande correctamente los logs al syslog. Por defecto los manda a la facility daemon.</p>
<p>Yo lo he probado ya en servidores en producción y por el momento funciona estupendamente.</p>
<p>Desde aquí agradezco el esfuerzo a <a href="http://mjdeboer.hyves.nl/">Marlon de Boer</a>, que no he conseguido encontrar un blog suyo donde hacerlo.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Another comparison of HAProxy and Nginx]]></title>
<link>http://affectioncode.wordpress.com/?p=29</link>
<pubDate>Sat, 28 Jun 2008 00:32:00 +0000</pubDate>
<dc:creator>Alexander</dc:creator>
<guid>http://affectioncode.wordpress.com/?p=29</guid>
<description><![CDATA[In my previous post about web application proxies, I compared HAProxy and Nginx performance when pr]]></description>
<content:encoded><![CDATA[<p>In my <a href="http://affectioncode.wordpress.com/2008/06/11/comparing-nginx-and-haproxy-for-web-applications/">previous post</a> about web application proxies, I compared HAProxy and Nginx performance when proxying a simple Rails application. While HAProxy was able to serve pages faster and more consistently, the beanchmark also uncovered an apparent design flaw in HAProxy that caused some connections to hang around in the queue for a long time. HAProxy's author, Willy Tarreau, quickly stepped in to attack the problem, and soon provided a <a href="http://haproxy.1wt.eu/download/1.3/src/">new point release</a>:</p>
<blockquote><p>My first analysis was that this problem was caused by "direct" requests (those with a server cookie) always being considered before the load balanced ones. But while fixing this design idiocy, I discovered a real problem : it was perfectly possible for a fresh new request to be served immediately without passing through the queue, causing requests in the queue to be delayed for at least as long as the queue timeout, until they might eventually expire. Now *that* explains the horrible peaks on Alexander's graphs. My problem was that it was a real misdesign, which could not be fixed by a 3-liner patch. So I spent the whole week reworking the queue management logic in a saner manner and running regression tests.</p></blockquote>
<p>The fix has further repercussions:</p>
<blockquote><p>[T]he good news is that not only this fixes a number of 503 errors and long response times when running with a low maxconn, but as an added bonus, the "redispatch" option is now naturally considered when a server's maxqueue is reached, so that it will now not be necessary anymore to trade between large queues and the risk of returning 503 errors.</p></blockquote>
<p>Willy also realized that his redesign work would lead the way to priority-based request scheduling in the future, which is great news.</p>
<p>With the new release in hand, I have finally found the time to sit down and do a rematch. The conclusion? In short, the patch works as intended: It eliminates the odd spikes while still providing smoother performance than Nginx. The spikes that remain are present with Nginx as well, and their regularity implies some kind of periodic activity, possibly on the box itself, although a much more likely culprit is Ruby's garbage collection. Damn you, curiously slow and old-fashioned interpreter implementation!</p>
<p>Finally, some people requested CPU usage data from vmstat. For this new benchmark I updated my scripts to run vmstat concurrently with ab, hoping there would some meaty differences for charting, but it turns out that there is no significant difference between HAProxy and Nginx — at best, CPU usage looks a trifle smoother with HAProxy, but this could be a fluke. I suspect you have to amp up the load considerably to achieve a sensible comparison. Still, I have included the vmstat data in the <a href="http://purefiction.net/paste/nginx_vs_haproxy_1.3.15.2.tar.bz2">raw data tarball</a> for anyone who is interested.</p>
<p>Anyway, enjoy the graphs. Many thanks to Willy for working out a solution so promptly and expertly.</p>
<p><strong>Nginx vs HAProxy at 3 concurrent connections</strong></p>
<p><a href="http://affectioncode.wordpress.com/files/2008/06/2ab_nginx_n1000_c3dat.png"><img class="alignnone size-medium wp-image-39" src="http://affectioncode.wordpress.com/files/2008/06/2ab_nginx_n1000_c3dat.png?w=300" alt="" width="240" height="180" /></a><a href="http://affectioncode.wordpress.com/files/2008/06/2ab_haproxy_n1000_c3dat.png"><img class="alignnone size-medium wp-image-36" src="http://affectioncode.wordpress.com/files/2008/06/2ab_haproxy_n1000_c3dat.png?w=300" alt="" width="240" height="180" /></a></p>
<p><strong>Nginx vs HAProxy at 10 concurrent connections</strong></p>
<p><a href="http://affectioncode.wordpress.com/files/2008/06/2ab_nginx_n1000_c10dat.png"><img class="alignnone size-medium wp-image-40" src="http://affectioncode.wordpress.com/files/2008/06/2ab_nginx_n1000_c10dat.png?w=300" alt="" width="240" height="180" /></a><a href="http://affectioncode.wordpress.com/files/2008/06/2ab_haproxy_n1000_c10dat.png"><img class="alignnone size-medium wp-image-37" src="http://affectioncode.wordpress.com/files/2008/06/2ab_haproxy_n1000_c10dat.png?w=300" alt="" width="240" height="180" /></a></p>
<p style="text-align:left;"><strong>Nginx vs HAProxy at 30 concurrent connections</strong></p>
<p><a href="http://affectioncode.wordpress.com/files/2008/06/2ab_nginx_n1000_c30dat.png"><img class="alignnone size-medium wp-image-41" src="http://affectioncode.wordpress.com/files/2008/06/2ab_nginx_n1000_c30dat.png?w=300" alt="" width="240" height="180" /></a><a href="http://affectioncode.wordpress.com/files/2008/06/2ab_haproxy_n1000_c30dat.png"><img class="alignnone size-medium wp-image-38" src="http://affectioncode.wordpress.com/files/2008/06/2ab_haproxy_n1000_c30dat.png?w=300" alt="" width="240" height="180" /></a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Scaling on EC2]]></title>
<link>http://webmynd.wordpress.com/?p=16</link>
<pubDate>Mon, 23 Jun 2008 19:38:11 +0000</pubDate>
<dc:creator>James Brady</dc:creator>
<guid>http://webmynd.wordpress.com/?p=16</guid>
<description><![CDATA[Like any application developed for a platform, the success of a Firefox Add-on is closely tied to th]]></description>
<content:encoded><![CDATA[<p>Like any application developed for a platform, the success of a Firefox Add-on is closely tied to the popularity and distribution you get from the underlying delivery mechanism. So, when we honed down the <a href="http://webmynd.com">WebMynd</a> feature set, improving the product enough to get on Mozilla's Recommended List, we were delighted by our increasing user numbers. A couple of weeks later, <a href="http://www.mozilla.com/en-US/firefox/all.html">Firefox 3</a> was released, and we got a usage graph like this:<a href="http://webmynd.files.wordpress.com/2008/06/usage1.png"><img class="aligncenter size-full wp-image-22" src="http://webmynd.wordpress.com/files/2008/06/usage1.png" alt="WebMynd usage statistics" width="500" height="177" /></a></p>
<p>With a product like WebMynd, where part of the service we provide is to save and index a person's web history, this sort of explosive expansion brings with it some growing pains. Performance was a constant battle with us, even with the relatively low user numbers of the first few months. This was due mainly to some poor technology choices; thankfully, the underlying architecture we chose from the start has proven to be sound.</p>
<p>I would not say that we have completely solved the difficult problem in front of us - we are still not content with the responsiveness of our service, and we're open about the brown-outs we still sometimes experience - but we have made huge progress and learned some invaluable lessons over the last few months.</p>
<p>What follows is a high level overview of some of the conclusions we've arrived at today, best practices that work for us and some things to avoid. In later weeks, I plan to follow up with deeper dives into certain parts of our infrastructure as and when I get a chance!</p>
<h2>Scaling is all about removing bottlenecks</h2>
<p>This sounds obvious, but should strongly influence all your technology and architecture decisions.</p>
<p>Being able to remove bottlenecks means you need to be able to swap out discrete parts which aren't performing well enough, and swap in bigger, faster, better parts which will perform as required. This will move the bottleneck somewhere else, at which point you need to swap out discrete parts which aren't performing well enough, and swap in bigger, faster, better parts... well you get the idea. This cycle can be repeated ad infinitum until you've optimised the heck out of everything and you're just <a href="http://www.techcrunch.com/2008/05/10/facebook-raises-another-100-million/">throwing machines at the problem</a>.</p>
<p>At WebMynd, for our search backend, we've done this four or five times already in the five months we've been alive, and I think I still have some iterations left in me. Importantly, I wouldn't say that any of these iterations were a mistake. In a parallel to the <a href="http://ycombinator.com/">Y Combinator</a> ethos of launching a product early, scaling should be an iterative process with as close a feedback loop as possible. Premature optimisation of any part of the service is a waste of time and is often <a href="http://www.acm.org/ubiquity/views/v7i24_fallacy.html">harmful</a>.</p>
<p>Scaling relies on having discrete pieces with clean interfaces, which can be iteratively improved.</p>
<h2>Horizontal is better than vertical</h2>
<p>One of the reasons Google triumphed in the search engine wars was that their core technology was designed from the ground up to scale horizontally across cheap hardware. Compare this with their competitors' approach, which was in general to scale vertically - using larger and larger monolithic machines glued together organically. Other search engines relied on <a href="http://en.wikipedia.org/wiki/Moore%27s_Law">improving hardware</a> to cope with demand, but when the growth of the internet outstripped available hardware, they had nowhere to go. Google was using inferior pieces of hardware, but had an architecture and infrastructure allowing for cheap and virtually limitless scaling.</p>
<p>Google's key breakthroughs were the <a href="http://labs.google.com/papers/gfs.html">Google File System</a> and <a href="http://labs.google.com/papers/mapreduce.html">MapReduce</a>, which together allow them to horizontally partition the problem of indexing the web. If you can architect your product in such a way as to allow for similar partitioning, scaling will be all the more easy. It's interesting to note that some of the current trends of Web2.0 products are extremely hard to horizontally partition, due to the hyper-connectedness of the user graph (witness <a href="http://twitter.com">Twitter</a>).</p>
<p>The problem WebMynd is tackling is <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly</a> partitionable. Users have their individual slice of web history, and these slices can be moved around the available hardware at will. New users equals new servers.</p>
<h2>Hardware is the lowest common denominator</h2>
<p>By running your application on virtual machines using <a href="http://www.amazon.com/ec2">EC2</a>, you are viewing the hardware you're running on as a commodity which can be swapped in and out at the click of a button. This is an useful mental model to have, where the actual machine images you're running on are just another component in your architecture which can be scaled up or down as demand requires. Obviously, if you're planning on scaling horizontally, you need to be building on a substrate which has low marginal cost for creating and destroying hardware - marginal cost in terms of time, effort and <a href="http://en.wikipedia.org/wiki/Capital_expenditure">capex</a>.</p>
<h2>A real example</h2>
<p>To put the above assertions into context, I'll use WebMynd's current architecture:<a href="http://webmynd.files.wordpress.com/2008/06/wm_arch3.png"><img class="aligncenter size-full wp-image-21" src="http://webmynd.wordpress.com/files/2008/06/wm_arch3.png" alt="WebMynd architecture" width="500" height="334" /></a></p>
<p>The rectangles represent EC2 instances. Their colour represents their function. The red arrow in the top right represents incoming traffic. Other arrows represent connectedness and flows of information.</p>
<p>This is a simplified example, but here's what the pieces do in general terms:</p>
<ul>
<li>All traffic is currently load balanced by a single <a href="http://haproxy.1wt.eu/">HAProxy</a> instance</li>
<li>All static content is served from a single <a href="http://nginx.net/">nginx</a> instance (with a hot failover ready)</li>
<li>Sessions are distributed fairly across lots of TurboGears application servers, on several machines</li>
<li>The database is a remote MySQL instance</li>
<li>Search engine updates are handled asynchronously through a queue</li>
<li>Search engine queries are handled synchronously over a direct TurboGears / Solr connection (not shown)</li>
</ul>
<p>One shouldn't be timid in trying new things to find the best solution; almost all of these parts have been iterated on like crazy. For example, we've used <a href="http://httpd.apache.org/">Apache</a> with <a href="http://www.modpython.org/">mod_python</a>, Apache with <a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html">mod_proxy</a>,  Apache with <a href="http://code.google.com/p/modwsgi/">mod_wsgi</a>. We've used <a href="http://dev.krys.ca/turbolucene">TurboLucene</a>, looked very hard at <a href="http://xapian.org/">Xapian</a>, various configurations of <a href="http://lucene.apache.org/solr/">Solr</a>.</p>
<p>For the queue, I've written my own queuing middleware, I've used <a href="http://activemq.apache.org/index.html">ActiveMQ</a> running on an EC2 instance and I'm now in the process of moving to Amazon's <a href="http://www.amazon.com/sqs">SQS</a>. We chose to use SQS as although ActiveMQ is free as in <a href="http://c2.com/cgi/wiki?FreeAsInBeer">beer</a> and <a href="http://c2.com/cgi/wiki?FreeAsInSpeech">speech</a>, it has an ongoing operations cost in terms of time, which is one thing you're always short of during hyper-growth.</p>
<p>The two parts which are growing the fastest are the web tier (the TurboGears servers) and the search tier (the Solr servers). However, as we can iterate on our implementations and rapidly horizontally scale on both of those parts, that growth has been containable, if not completely pain free.</p>
<p>&#160;<br />
Amazon's Web Services give growing companies the ideal building blocks to scale and keep up with demand. By iteratively improving the independent components in our architecture, we have grown to meet the substantial challenge of providing the WebMynd service to our users.<br />
&#160;</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[High performance PHP]]></title>
<link>http://alword.wordpress.com/?p=15</link>
<pubDate>Thu, 19 Jun 2008 22:11:38 +0000</pubDate>
<dc:creator>alword</dc:creator>
<guid>http://alword.wordpress.com/?p=15</guid>
<description><![CDATA[If you have the need to run php with a very high traffic you should think about the follwoing setup.]]></description>
<content:encoded><![CDATA[<p>If you have the need to run php with a very high traffic you should think about the follwoing setup.</p>
<p>Don't think it will work in 5 minutes and you don't need some knowledge about how to setup an webserver and a php application, you definitely need it.</p>
<p>If you think this is a step by step description for people which only want to copy and past commands and it works then you are wrong here, please take a websearch engine for a alternative description.</p>
<p>What you need:</p>
<ol>
<li>nginx <a title="nginxhome" href="http://www.nginx.net/" target="_blank">http://www.nginx.net/</a></li>
<li>php-fm <a title="php-fmlink" href="http://php-fpm.anight.org/" target="_blank">http://php-fpm.anight.org/</a></li>
<li>php http://www.php.net/</li>
<li>a compile environment</li>
<li>the development libraries for the wanted php features and libxml2</li>
<li>A clear test scenario and target how many requests per second should be reached on static and dynamic part.</li>
</ol>
<p>How you can build this environment:</p>
<ol>
<li>Extract, build and install nginx <a title="nginxgettingstarted" href="http://wiki.codemongers.com/NginxGettingStarted">http://wiki.codemongers.com/NginxGettingStarted</a></li>
<li>Extract, build   and install php-fm <a title="php-fmdoc" href="http://php-fpm.anight.org/docs.html" target="_blank">http://php-fpm.anight.org/docs.html</a></li>
<li>configure nginx for fast-cgi proxying <a title="nginxfcgimod" href="http://wiki.codemongers.com/NginxHttpFcgiModule" target="_blank">http://wiki.codemongers.com/NginxHttpFcgiModule</a></li>
</ol>
<p><img src="http://none.at/high-perf-php.gif" alt="High Performance View" /></p>
<p>A brief description how the flow is:</p>
<ul>
<li>A request comes to nginx</li>
<li>He takes a look into his config to find the right <a title="nginxlocationlink" href="http://wiki.codemongers.com/NginxHttpCoreModule#location" target="_blank">location</a> or <a title="nginxserverlink" href="http://wiki.codemongers.com/NginxHttpCoreModule#server" target="_blank">server</a> config</li>
<li>If the static content rule matches then he will deliver the content directly from the disc</li>
<li>If the dynamic rule matches the he will contact php-fm, which manage the php-instances</li>
<li>php-fm execute the php script and send the dynamic content back to nginx</li>
<li>nginx sends the content back to the client</li>
</ul>
<p>There are some pitfalls:</p>
<ol>
<li><a title="nginxclienbodbufsizlink" href="http://wiki.codemongers.com/NginxHttpCoreModule#client_body_buffer_size" target="_blank">client_body_buffer_size</a></li>
<li><a title="nginxfastcgibodbufsizlink" href="http://wiki.codemongers.com/NginxHttpFcgiModule#fastcgi_buffers" target="_blank">fastcgi_buffers*</a></li>
</ol>
<p>You should take your time to find the right config setup for nginx and php-fm to be able to fulfill the assumed traffic.</p>
<p>I have started to translate the russian documentation, which is still not complete.</p>
<p>You can take a look here:</p>
<p><a title="phpfmcurrprobs" href="http://none.at/phpfm/docs/current_php_fastcgi_problems_en.html" target="_blank">why_fastcgi_en</a></p>
<p><a title="phpfmcurrprobs" href="http://none.at/phpfm/docs/current_php_fastcgi_problems_en.html" target="_blank">current_php_fastcgi_problems_en</a></p>
<p><a title="phpfmextrafeatures" href="http://none.at/phpfm/docs/extra_features_en.html" target="_blank">extra_features_en</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[use the event ports in nginx]]></title>
<link>http://alword.wordpress.com/?p=13</link>
<pubDate>Sat, 14 Jun 2008 08:45:42 +0000</pubDate>
<dc:creator>alword</dc:creator>
<guid>http://alword.wordpress.com/?p=13</guid>
<description><![CDATA[Solaris have since version 10 a new polling infrastrucutre Event Ports here a more detailed article ]]></description>
<content:encoded><![CDATA[<p>Solaris have since version 10 a new polling infrastrucutre <a title="Event Ports" href="http://docs.sun.com/app/docs/doc/817-0547/whatsnew-196?l=en&#38;a=view&#38;q=event+port" target="_blank">Event Ports</a> here a more detailed article about <a title="Event Ports Framework" href="http://developers.sun.com/solaris/articles/event_completion.html" target="_blank">Event Completion Framework</a>. <a title="AdLe" href="http://www.opensolaris.org/viewProfile.jspa?id=21" target="_blank">Adam Leventhal</a> wrotes in his <a title="AhlBlog" href="http://blogs.sun.com/ahl/" target="_blank">Blog</a> for him this is one of the top <a title="top20" href="http://blogs.sun.com/ahl/date/20040712" target="_blank">20 best thing in Solaris 10</a>.</p>
<p>By default nginx do not use this event methode due to the fact that there was some security related problems <a title="EvPortSecProblem1" href="http://sunsolve.sun.com/search/document.do?assetkey=1-26-102485-1" target="_blank">Security Vulnerabilities in The Solaris Event Port API May Result in a Denial of Service (DoS) Condition</a> and  <a title="EvPortSecProblem" href="http://sunsolve.sun.com/search/document.do?assetkey=1-66-235122-1" target="_blank">Vulnerability in the Solaris 10 Event Port Implementation May Lead to a System Panic, Resulting in a Denial of Service (DoS)</a> if you have a newer Version or applied the Patch you should use the event ports in nginx.</p>
<p>You only need to add</p>
<blockquote><p>use eventport;</p></blockquote>
<p>in the <strong>events { ... }</strong> section. If you don't add this then nginx by default us the <a title="devpoll" href="http://developers.sun.com/solaris/articles/polling_efficient.html" target="_blank">/dev/poll</a> method.</p>
<p>More about the possible polling methods can be found <a title="nginxoptis" href="http://wiki.codemongers.com/NginxOptimizations">here</a>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[nginx build on opensolaris with SunStudio]]></title>
<link>http://alword.wordpress.com/?p=9</link>
<pubDate>Fri, 13 Jun 2008 14:47:13 +0000</pubDate>
<dc:creator>alword</dc:creator>
<guid>http://alword.wordpress.com/?p=9</guid>
<description><![CDATA[Today I was interested if the latest nginx (nginx-0.7.1) is able to build on the opensolaris box and]]></description>
<content:encoded><![CDATA[<p>Today I was interested if the latest nginx (nginx-0.7.1) is able to build on the opensolaris box and YES it does ;-)</p>
<p>1.) get it</p>
<blockquote><p>wget http://sysoev.ru/nginx/nginx-0.7.1.tar.gz</p></blockquote>
<p>2.) extract it</p>
<blockquote><p>gtar xfvz nginx-0.7.1.tar.gz</p></blockquote>
<p>3.) build it</p>
<blockquote><p>cd nginx-0.7.1 &#38;&#38; ./configure --prefix=$HOME/servers/nginx --with-http_ssl_module --with-debug --with-cc=/opt/SunStudioExpress/bin/cc</p></blockquote>
<p>It's so easy, thanks Igor.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Install Deki Wiki on Nginx Ubuntu - Nginx Conf File Included]]></title>
<link>http://honewatson.wordpress.com/?p=312</link>
<pubDate>Fri, 13 Jun 2008 03:51:23 +0000</pubDate>
<dc:creator>honewatson</dc:creator>
<guid>http://honewatson.wordpress.com/?p=312</guid>
<description><![CDATA[Deki Wiki is cool but Apache is really too bloated.
Here&#8217;s how to get it working on Nginx Ubun]]></description>
<content:encoded><![CDATA[<p>Deki Wiki is cool but Apache is really too bloated.</p>
<p>Here's how to get it working on Nginx Ubuntu.</p>
<p><!--more--></p>
<p>Follow the instructions for the source installation.  Do not apt-get apache and apache associated libraries.  <a href="http://wiki.developer.mindtouch.com/Deki_Wiki/Installation_and_Upgrade/1.9.0_Itasca_Source_Code_Install_and_Upgrade_Guide">Source installation.</a></p>
<p>I presume you already have mysql and php installed.</p>
<p class="code"><code><br />
apt-get install imagemagick wv pdftohtml html2text html2ps htmldoc aspell links mono-gmcs mono-mcs libmono-sqlite2.0-cil libmono-sqlite2.0-cil libmono-system-web2.0-cil<br />
</code></p>
<p>Note the above may not be all you need.  The complete package list is at <a href="http://wiki.developer.mindtouch.com/Deki_Wiki/Installation_and_Upgrade/1.9.0_Itasca_Source_Code_Install_and_Upgrade_Guide">Source installation</a>.</p>
<p>Make sure pear is installed.... aptitude install php-pear</p>
<p>There are problems with /skins/ace/neutral/css.php files etc.  Sometimes they these files can't find the includes files so you may have to edit these and put the full path for these includes.</p>
<p>After the full install you may have to also <strong>aptitude install libmono-i18n2.0-cil</strong> otherwise you might get some 500 errors with mysql.</p>
<p>If you get an error with @api you may have to change the /etc/dekiwiki/mindtouch.host.conf</p>
<blockquote><p># hostname to listen on<br />
IP="*:8081"</p></blockquote>
<p>Note I also had to:</p>
<blockquote><p>cp source_folder/config/dekiwiki-init.debian /etc/init.d/dekiwiki &#38;&#38; chmod +x /etc/init.d/dekiwiki</p>
<p>mkdir /var/www/.wapi
</p></blockquote>
<p>server {<br />
listen       80;<br />
server_name wiki.mookiesplace.com;<br />
access_log  /usr/local/nginx/logs/campaign.access.log;</p>
<p>location ~* ^.+\.(html&#124;jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js)$<br />
{<br />
root /home/mookiesplace/dekiwiki;<br />
expires 10d;<br />
break;<br />
error_page 404 /index.php?title=$uri;<br />
}</p>
<p>location /      {<br />
root   /home/jollymarketing/campaignwiki;<br />
index index.php;</p>
<p>rewrite ^/$ /index.php?title= last;<br />
rewrite ^/@gui/(.*)$ /proxy.php?path=$1 last;</p>
<p>if (!-e $request_filename) {<br />
rewrite ^/(.+)$ /index.php?title=$1 last;<br />
}<br />
}</p>
<p>location /@api {<br />
proxy_pass http://127.0.0.1:8081;<br />
}</p>
<p>location ~ \.php$ {<br />
fastcgi_pass   127.0.0.1:8084;<br />
fastcgi_index  index.php;<br />
fastcgi_param  SCRIPT_FILENAME /home/mookiesplace/dekiwiki$fastcgi_script_name;<br />
include        /usr/local/nginx/conf/fastcgi_params;<br />
}<br />
error_page   500 502 503 504  /50x.html;</p>
<p>location = /50x.html {<br />
root   /var/www/nginx-default;<br />
}</p>
<p>}</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Comparing Nginx and HAProxy for web applications]]></title>
<link>http://affectioncode.wordpress.com/?p=3</link>
<pubDate>Tue, 10 Jun 2008 23:13:15 +0000</pubDate>
<dc:creator>Alexander</dc:creator>
<guid>http://affectioncode.wordpress.com/?p=3</guid>
<description><![CDATA[The last few days I have been comparing Nginx to HAProxy, with surprising results.
First, a bit of ]]></description>
<content:encoded><![CDATA[<p style="text-align:left;">The last few days I have been comparing Nginx to HAProxy, with surprising results.</p>
<p style="text-align:left;">First, a bit of background. For a long time we at Bengler have been using Nginx as the main web server for our projects (<a href="http://underskog.no/">1</a>, <a href="http://origo.no/">2</a>), as well as to proxy Rails running under Mongrel. Nginx is a superb little open-source web server with a small footprint, sensible configuration language, modern feature set and buckets of speed. However, we quickly realized that the load balancing features of the proxy are not up to scratch.</p>
<p style="text-align:left;">The core problem is the proxy load balancing algorithm. Nginx only comes with a round-robin balancer and a hash-based balancer. Only the former is of interest to us since our object is to distribute the load evenly across a pack of Mongrel back ends. The round-robin algorithm is often an acceptable tool: if every request finishes within a few milliseconds, there's no problem.</p>
<p style="text-align:left;">But if a page takes a while to load, Nginx will start routing requests to backends that are already processing requests — as a result, some backends will be queueing up requests while some backends will remain idle. You will get an uneven load distribution, and the unevenness will increase with the amount of load subject to the load-balancer.</p>
<p style="text-align:left;">So when Gzegorz Nosek, backed by <a href="http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel">EngineYard</a>, announced his <a href="http://git.localdomain.pl/?p=nginx-upstream-fair.git;a=summary">fair load balancer</a> module, we naturally pounced on it. Gzegorz's module routes requests to the back end with the fewest outstanding requests, and this improved performance a lot.</p>
<p style="text-align:left;">Unfortunately, Gzegorz's patch is not completely stable, and turned out to be the main source of our stability problems of late. Sometimes it sits down chewing the carpet while backends go idle and requests pile up, or worse, goes into tailspin and refuses to serve requests, for which the only remedy is a cold restart of Nginx. Even in normal operation, however, it will often send multiple connections to a backend even when some are idle, since there is no limit on the number of connections each backend can receive.</p>
<p style="text-align:left;">After reading about <a href="http://haproxy.1wt.eu/">HAProxy</a> (there's nice blog Rails-oriented blog post <a href="http://www.igvita.com/2008/05/13/load-balancing-qos-with-haproxy/">here</a>), I felt the itch to try out this product myself. HAProxy has a handsome feature set:</p>
<ul style="text-align:left;">
<li><strong>It's is proxy — and only a proxy.</strong> It can't serve files, for example: proxying is all its does.</li>
<li>It can proxy anything TCP-based — not just HTTP.</li>
<li>Plenty of load-balancing algorithms, <strong>including a "least connections" strategy</strong> that picks the backend with the fewest pending connections. Which happens to be just what we want.</li>
<li>Backends can be sanity- and health-checked by URL to avoid routing requests to brain-damaged backends. (It can even stagger these checks to avoid spikes.)</li>
<li><strong>A dedicated </strong><a href="http://www.igvita.com/posts/05-08/haproxy-large.png"><strong>status page</strong></a> gives you backend status, uptime and lots of yummy metrics. There's also a way to read metrics from a Unix domain socket.</li>
<li>Requests can be routed based on all sorts of things: cookies, URL substrings, client IP, etc.</li>
</ul>
<div style="text-align:left;">
<p>I like the fact that HAProxy is so single-minded in its approach. Experience tells me that simple, specialized, single-purpose applications are preferable over complex, flexible one-size-fits-all applications, <a href="http://varnish.projects.linpro.no/">Varnish</a> and <a href="http://www.danga.com/memcached/">Memcached</a> being two relevant examples.</p>
<p>To determine if HAProxy is up to par, I have done a few simple benchmarks. They're not awesomely scientific, but I think they are good enough.</p>
<p><strong>The setup</strong>: Dedicated test machine (quad-core AMD64 2.4GHz, 4GB RAM), 3 mongrels running an actual Rails 1.2 app. I use Apache's ab benchmarking tool for the testing (many people prefer httperf, but we have never quite seen eye to eye) and I run 1,000 requests at various levels of concurrency. The page being tested is a minimal controller action that makes one database call, one Memcached lookup and renders an empty page; it takes about 20ms to render.</p>
<p>I have configured Nginx with Gzegorz's fair load-balancing patch. The configuration does nothing except set up a proxy against Mongrel.</p>
<p>I have configured HAProxy with the "leastconns" algorithm and "maxconn 1" for each Mongrel. This is intentionally unfair — but the object is not a comparison of HAProxy and Nginx when each is configured identically; rather, I would like to observe what kind of performance profile can be achieved with HAProxy's superior gadgetry.</p>
<p>The "maxconns" setting is significant — since only a single request is handed to Mongrel at a time, it means that when all backends are busy, pending client requests will idle inside HAProxy — rather than inside Mongrel. Subsequently, when a backend becomes available, the next request in line will be routed to that backend. Without this restriction, of course, requests would end up in busy Mongrels and sit there even though other backends might be available.</p>
<p>Nginx, using the fair load-balancing patch, will behave similarly, but will suffer occasionally overlapping requests since it has no limit on the number of connections each back end can receive.</p>
<p><strong>So, the data</strong>. The following graphs show the response times of each request.</p>
<p style="text-align:center;"><strong>Nginx — 3 concurrent connections</strong></p>
<p style="text-align:center;"><a href="http://affectioncode.wordpress.com/files/2008/06/new_ab_nginx_n1000_c3dat.png"><img class="alignnone size-full wp-image-21" src="http://affectioncode.wordpress.com/files/2008/06/new_ab_nginx_n1000_c3dat.png" alt="Nginx — 3 concurrent connections" width="400" height="300" /></a></p>
<p style="text-align:center;"><strong>HAProxy — 3 concurrent connections</strong></p>
<p style="text-align:center;"><a href="http://affectioncode.wordpress.com/files/2008/06/new_ab_haproxy_n1000_c3dat.png"><img class="alignnone size-full wp-image-17" src="http://affectioncode.wordpress.com/files/2008/06/new_ab_haproxy_n1000_c3dat.png" alt="HAProxy — 3 concurrent connections" width="400" height="300" /></a></p>
<p style="text-align:center;"><strong>Nginx — 10 concurrent connections</strong></p>
<p style="text-align:center;"><a href="http://affectioncode.wordpress.com/files/2008/06/new_ab_nginx_n1000_c10dat.png"><img class="alignnone size-full wp-image-22" src="http://affectioncode.wordpress.com/files/2008/06/new_ab_nginx_n1000_c10dat.png" alt="Nginx — 10 concurrent connections" width="400" height="300" /></a></p>
<p style="text-align:center;"><strong>HAProxy — 10 concurrent connections</strong></p>
<p style="text-align:center;"><a href="http://affectioncode.wordpress.com/files/2008/06/new_ab_haproxy_n1000_c10dat.png"><img class="alignnone size-full wp-image-18" src="http://affectioncode.wordpress.com/files/2008/06/new_ab_haproxy_n1000_c10dat.png" alt="HAProxy — 10 concurrent connections" width="400" height="300" /></a></p>
<p style="text-align:center;"><strong>Nginx — 30 concurrent connections</strong></p>
<p style="text-align:center;"><a href="http://affectioncode.wordpress.com/files/2008/06/new_ab_nginx_n1000_c30dat.png"><img class="alignnone size-full wp-image-23" src="http://affectioncode.wordpress.com/files/2008/06/new_ab_nginx_n1000_c30dat.png" alt="Nginx — 10 concurrent connections" width="400" height="300" /></a></p>
<p style="text-align:center;"><strong>HAProxy — 30 concurrent connections</strong></p>
<p style="text-align:center;"><a href="http://affectioncode.files.wordpress.com/2008/06/new_ab_haproxy_n1000_c30dat1.png"><img class="alignnone size-full wp-image-25" src="http://affectioncode.wordpress.com/files/2008/06/new_ab_haproxy_n1000_c30dat1.png" alt="HAProxy — 30 concurrent connections" width="400" height="300" /></a></p>
<p style="text-align:left;">HAproxy comes out on top with regard to requests/second — at 30 concurrent connections, we get 218 req/s compared to 162 req/s for Nginx — but the real difference here is in the distribution of response time.</p>
<p>At 3 concurrent connections, Nginx begins to serve <em>every</em> request a bit more slowly, whereas HAProxy at 10 concurrnet connections manages to deliver 95% of the requests all within the time of the fastest request. At the same time, Nginx performance is all over the map while HAProxy remains fairly consistent. Unfortunately, this evenness happens at the expense of returning a small number of connections extremely slowly.</p>
<p>I'm uncertain if HAProxy imposes an absolute ordering on the request queue; since backends tend to be full, perhaps some connections simply sit around for a long time without being scheduled. That would explain the blips on the graph; in one test session I had a single request taking 47 seconds.</p></div>
<p style="text-align:left;">In a real-world situation, some of these requests would simply time out, hopefully to be rescued by a friendly "sorry, we're overloaded" error page. Is this an acceptable compromise between performance and responsiveness? I think it is, given that they should only occur during exceptional load; in such situations I prefer serving really fast pages to most users and possibly disappointing an extremely small number of users, rather than letting everyone suffer.</p>
<p style="text-align:left;">I think these results show that HAProxy is a better choice for us. The additional features and fine-grained proxy control are also extremely welcome. HAProxy's lack of support for sharing static files means that we will also put Nginx behind HAProxy and route requests accordingly.</p>
<p style="text-align:left;">You can <a href="http://purefiction.net/paste/haproxy_vs_nginx_data.tar.bz2">download the raw data here</a>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Google App Engine SDK Nginx Proxy Pass proxy_pass Ubuntu]]></title>
<link>http://bookmarks.honewatson.com/2008/05/28/google-app-engine-sdk-nginx-proxy-pass-proxy_pass-ubuntu/</link>
<pubDate>Wed, 28 May 2008 08:53:38 +0000</pubDate>
<dc:creator>honewatson</dc:creator>
<guid>http://bookmarks.honewatson.com/2008/05/28/google-app-engine-sdk-nginx-proxy-pass-proxy_pass-ubuntu/</guid>
<description><![CDATA[Here&#8217;s a quick set up for Google App Engine&#8217;s SDK on Nginx.



server {
listen       80;]]></description>
<content:encoded><![CDATA[<p>Here's a quick set up for Google App Engine's SDK on Nginx.</p>
<p><!--more--></p>
<p class="code">
<code><br />
server {<br />
listen       80;<br />
server_name  yourhotdomain.com;<br />
access_log  logs/yourhotdomain.access.log;<br />
location / {<br />
proxy_pass  http://localhost:8080;<br />
}<br />
}<br />
</code>
</p>
<p>If you want to change the datastore location do this:</p>
<p class="code">
<code><br />
sudo ./dev_appserver.py helloworld/<br />
ctrl c<br />
cp /tmp/dev_appserver.datastore /some_new_path/dev_appserver.datastore<br />
sudo ./dev_appserver.py --datastore_path=/some_new_path/dev_appserver.datastore helloworld/<br />
</code>
</p>
<p>Your App Engine app should now be running on 'yourhotdomain.com'.</p>
<p>If you want to run it on your local computer just change your /etc/hosts file to include 'yourhotdomain.com'</p>
<p class="code">
<code><br />
127.0.0.1      yourhotdomain.com	yourhotdomain.com<br />
</code></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Install and configure NGINX  and Mongrel for Rails]]></title>
<link>http://laurentbois.wordpress.com/?p=294</link>
<pubDate>Tue, 06 May 2008 10:10:59 +0000</pubDate>
<dc:creator>lbois</dc:creator>
<guid>http://laurentbois.wordpress.com/?p=294</guid>
<description><![CDATA[Some times ago i wrote an article about installing a Rails stack on Debian Etch (our production serv]]></description>
<content:encoded><![CDATA[<p>Some times ago i wrote an article about installing a Rails stack on Debian Etch (our production server), then how to configure Apache 2 + fcgid to run our Rails app.</p>
<p>After several tests with this deployment configuration , we encountered some problems of performance (i will detail what our application does in a future article) :</p>
<p>- First with Apache server, after an idle time, then accessing a page of our application, we should wait for a long time before our page loads. Seems fcgid processes take a long time to (re)start.</p>
<p>- In our application, we deliver some files with a download controller : for bigger files, the download was very long.</p>
<p>We decided recently to switch the Apache2 / fcgid  configuration to Mongrel (Ruby HTTP server) + nginx (as proxy in front of Mongrel).</p>
<p><!--more--></p>
<p>I will explain you how to proceed.</p>
<p>We suppose here you have already installed Ruby , Rails, mySQL.</p>
<p>Connect as root and follow these steps :</p>
<p><strong>First stop Apache2 :</strong></p>
<p>#/etc/init.d/apache2 stop</p>
<p><strong>Install Mongrel</strong></p>
<p># gem install mongrel</p>
<p># gem install mongrel_cluster</p>
<p><strong>Install nginx:</strong></p>
<p># aptitude install nginx</p>
<p><strong>Configure what we have installed</strong></p>
<p>We have to setup our server apps to boot when the server starts, and shutdown gracefully when the server reboots.</p>
<p>Concerning nginx, it already did automatically this setup at install:</p>
<p># ls -l /etc/rc?.d/*nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc0.d/K20nginx -&#62; ../init.d/nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc1.d/K20nginx -&#62; ../init.d/nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc2.d/S20nginx -&#62; ../init.d/nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc3.d/S20nginx -&#62; ../init.d/nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc4.d/S20nginx -&#62; ../init.d/nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc5.d/S20nginx -&#62; ../init.d/nginx<br />
lrwxrwxrwx 1 root root 15 2008-05-05 11:00 /etc/rc6.d/K20nginx -&#62; ../init.d/nginx</p>
<p>As you can see, for runlevels 0, 1 and 6 there is a <strong>K</strong> at the beginning of the link, for runlevels 2, 3, 4 and 5, there is a <strong>S</strong>. Those two letters stands for <strong>K</strong><em>ill</em> and <strong>S</strong><em>tart</em>.<br />
On Debian (and Ubuntu), runlevels 2, 3, 4 and 5 are multi-users runlevels.<br />
Runlevel 0 is <em>Halt</em>.<br />
Runlevel 1 is <em>single user mode</em><br />
Runlevel 6 is <em>reboot</em></p>
<p><strong>Remove Apache 2 service</strong></p>
<p>By hand you should remove every link /etc/rc.X/*apache2.</p>
<p>Using update-rc.d is as simple as :</p>
<p># update-rc.d -f apache2 remove</p>
<p>Removing any system startup links for /etc/init.d/apache2 ...<br />
/etc/rc0.d/K09apache2<br />
/etc/rc1.d/K09apache2<br />
/etc/rc2.d/S91apache2<br />
/etc/rc3.d/S91apache2<br />
/etc/rc4.d/S91apache2<br />
/etc/rc5.d/S91apache2<br />
/etc/rc6.d/K09apache2</p>
<p><strong>Add Mongrel service for automatic startup/stop</strong></p>
<p># cp /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/mongrel_cluster</p>
<p>Edit /etc/init.d/mongrel_cluster and add the following environment setup:</p>
<pre>PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/sbin:/usr/local/bin</pre>
<p># chmod +x /etc/init.d/mongrel_cluster</p>
<p># update-rc.d mongrel_cluster defaults<br />
Adding system startup for /etc/init.d/mongrel_cluster ...<br />
/etc/rc0.d/K20mongrel_cluster -&#62; ../init.d/mongrel_cluster<br />
/etc/rc1.d/K20mongrel_cluster -&#62; ../init.d/mongrel_cluster<br />
/etc/rc6.d/K20mongrel_cluster -&#62; ../init.d/mongrel_cluster<br />
/etc/rc2.d/S20mongrel_cluster -&#62; ../init.d/mongrel_cluster<br />
/etc/rc3.d/S20mongrel_cluster -&#62; ../init.d/mongrel_cluster<br />
/etc/rc4.d/S20mongrel_cluster -&#62; ../init.d/mongrel_cluster<br />
/etc/rc5.d/S20mongrel_cluster -&#62; ../init.d/mongrel_cluster</p>
<p>But as you can see, the default value is 20 which is pretty different than 91 ... a S20 link is started before a S91 and and K91 is kill before K20.</p>
<p>I decided to startup nginx after mongrel, and stop nginx before mongrel. I'll use 23 for nginx.</p>
<p>First remove nginx symlinks:</p>
<p># update-rc.d -f nginx remove</p>
<p>Then create symlinks for nginx with custom priorities :</p>
<p># update-rc.d nginx defaults 23 23<br />
Adding system startup for /etc/init.d/nginx ...<br />
/etc/rc0.d/K23nginx -&#62; ../init.d/nginx<br />
/etc/rc1.d/K23nginx -&#62; ../init.d/nginx<br />
/etc/rc6.d/K23nginx -&#62; ../init.d/nginx<br />
/etc/rc2.d/S23nginx -&#62; ../init.d/nginx<br />
/etc/rc3.d/S23nginx -&#62; ../init.d/nginx<br />
/etc/rc4.d/S23nginx -&#62; ../init.d/nginx<br />
/etc/rc5.d/S23nginx -&#62; ../init.d/nginx<br />
Create the folder /etc/mongrel_cluster that our Rails app Mongrel config will live in.</p>
<p># mkdir /etc/mongrel_cluster</p>
<p>Generate the Rails app Mongrel config file:</p>
<p># mongrel_rails cluster::configure -e production -p 8001 -N 3 -c /path/to/rails/app -C /path/to/rails/app/config/mongrel_cluster.yml -P /path/to/rails/app/log/mongrel.pid -l /path/to/rails/app/log/mongrel.log --user &#60;user&#62; --group &#60;group&#62;  -a 127.0.0.1</p>
<p>Verify the config file (/path/to/rails/app/config/mongrel_cluster.yml)</p>
<p>user: &#60;user&#62;<br />
cwd: /path/to/rails/app<br />
log_file: /path/to/rails/app/log/mongrel.log<br />
port: "8001"<br />
environment: production<br />
group: &#60;group&#62;<br />
address: 127.0.0.1<br />
pid_file: /path/to/rails/app/mongrel.pid<br />
servers: 3</p>
<p>Create a symlink to this file into /etc/mongrel_cluster :</p>
<pre>ln -s /path/to/your/rails/app/mongrel_cluster.yml /etc/mongrel_cluster/YOURAPPNAME.yml</pre>
<p><strong>Configure nginx</strong></p>
<p>We now need to edit our nginx.conf file found in <strong>/etc/nginx/nginx.conf</strong> to set it up. Edit the values found in my <a href="http://laurentbois.wordpress.com/files/2008/05/nginx.pdf" target="_blank">nginx.conf</a> file and modify it to suit your needs.</p>
<p>Nginx is a powerful UNIX tool.</p>
<p>You have noticed we used here <a href="http://nginx.net/" target="_blank">nginx</a> as Reverse-Proxy in front of a Mongrel cluster; if the web-server (Mongrel in our case) cannot handle more load , you can even put nginx before the web-server to use it as web-server to handle requests to static files.</p>
<p>Thanks to nginx flexibility, you can pass any types of requests to web-server server by using <tt>location</tt> sections (all files, only dynamic content requests or some specific locations in your web-server tree):</p>
<div class="codecolorer-container nginx">
<div class="codecolorer" style="font-family:monospace;"><span class="kw1">location</span> / <span class="br0">{</span><br />
<span class="kw2">proxy_pass</span> <span class="re2">http://mongrel:<span class="nu0">8000</span>/</span>;<br />
<span class="kw2">proxy_set_header</span> <span class="kw4">X-Real-IP</span> <span class="re0">$remote_addr</span>;<br />
<span class="br0">}</span></div>
</div>
<p>It should be fine now! Reboot your server and test everything is up after startup :</p>
<p># shutdown -r now<br />
Nota : Another tool to test: <a href="nginx google analytics top 5" target="_blank">Varnish</a>, an high-performance HTTP-accelerator.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Load Balancer Update]]></title>
<link>http://barry.wordpress.com/?p=191</link>
<pubDate>Mon, 28 Apr 2008 18:47:11 +0000</pubDate>
<dc:creator>Barry</dc:creator>
<guid>http://barry.wordpress.com/?p=191</guid>
<description><![CDATA[A while back, I posted about some testing we were doing of various software load balancers for WordP]]></description>
<content:encoded><![CDATA[<p>A while back, I <a href="http://barry.wordpress.com/2006/08/30/load-balancer-testing/">posted</a> about some testing we were doing of various software load balancers for WordPress.com.  We chose to use <a href="http://www.apsis.ch/pound/">Pound</a> and have been using it past 2-ish years.  We started to run into some issues, however, so we starting looking elsewhere.  Some of these problems were:</p>
<ul>
<li>Lack of true configuration reload support made managing our 20+ load balancers cumbersome.  We had a solution (hack) in place, but it was getting to be a pain.</li>
<li>When something would break on the backend and cause 20-50k connections to pile up, the thread creation would cause huge load spikes and sometimes render the servers useless.</li>
<li>As we started to push 700-1000 requests per second per load balancer, it seemed things started to slow down.  Hard to get quantitative data on this because page load times are dependent on so many things.</li>
</ul>
<p>So...  A couple weeks ago we finished converting all our load balancers to <a href="http://nginx.net/">Nginx</a>.  We have been using Nginx for <a href="http://en.gravatar.com/">Gravatar</a> for a few months and have been impressed by its performance, so moving WordPress.com over was the obvious next step.  Here is a graph that shows CPU usage before and after the switch.  Pretty impressive!</p>
<p><a href="http://barry.files.wordpress.com/2008/04/nginx-cpu.png"><img class="aligncenter size-full wp-image-192" src="http://barry.wordpress.com/files/2008/04/nginx-cpu.png" alt="" width="450" height="343" /></a>  </p>
<p>Before choosing nginx, we looked at <a href="http://haproxy.1wt.eu/">HAProxy</a>, <a href="http://www.danga.com/perlbal/">Perlbal</a>, and <a href="http://www.linuxvirtualserver.org/">LVS</a>. Here are some of the reasons we chose Nginx:</p>
<ul>
<li>Easy and flexible configuration (true config "reload" support has made my life easier)</li>
<li>Can also be used as a web server, which allows us to simplify our software stack (we are not using nginx as a web server currently, but may switch at some point).</li>
<li>Only software we tested which could handle 8000 (live traffic, not benchmark) requests/second on a single server</li>
</ul>
<div>We are currently using Nginx 0.6.29 with the <a href="http://wiki.codemongers.com/NginxHttpUpstreamRequestHashModule">upstream hash module</a>  which gives us the <a href="http://barry.wordpress.com/2007/11/01/static-hostname-hashing-in-pound/">static hashing</a> we need to proxy to varnish.  We are regularly serving about 8-9k requests/second  and about 1.2Gbit/sec through a few Nginx instances and have plenty of room to grow!</div>
<p> </p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Nginx SuperCache WP Super Cache Plugin Rewrites Wordpress Mu]]></title>
<link>http://bookmarks.honewatson.com/2008/04/24/nginx-supercache-wp-super-cache-plugin-rewrites-wordpress-mu/</link>
<pubDate>Thu, 24 Apr 2008 01:39:28 +0000</pubDate>
<dc:creator>honewatson</dc:creator>
<guid>http://bookmarks.honewatson.com/2008/04/24/nginx-supercache-wp-super-cache-plugin-rewrites-wordpress-mu/</guid>
<description><![CDATA[Nginx combined with WP Super Cache for WordPress Mu is an interesting idea.  However, you can potent]]></description>
<content:encoded><![CDATA[<p>Nginx combined with WP Super Cache for Wordpress Mu is an interesting idea.  However, you can <a href="http://www.ruby-forum.com/topic/140396">potentially set up</a> a simpler, and superior caching system using internal Nginx features that replaces the need for Super Cache.</p>
<p><!--more--></p>
<p>I will be working on this WP Super Cache replacement using Nginx but in the mean time here is a set up for Nginx and WP Super Cache rewrites.</p>
<p>First you need install 0.6.29 or up which has a module called Gzip Pre-Compression Module.  Download and unzip the latest Nginx.  Then set it up like this:</p>
<p class="code">
<code><br />
./configure --with-http_gzip_static_module  --with-http_ssl_module<br />
make<br />
sudo make install<br />
</code>
</p>
<p>In the http area of your nginx.conf file include:</p>
<p class="code">
<code><br />
gzip_static on;<br />
gzip_http_version   1.1;<br />
gzip_proxied        expired no-cache no-store private auth;<br />
gzip_disable        "MSIE [1-6]\.";<br />
gzip_vary           on;<br />
</code>
</p>
<p>Now what the above setting does is makes Nginx first see if there is a file in the directory already gzipped.  If there is no gzip file Nginx will gzip the file on the fly then send the file out.</p>
<p>Now for the rewrites:</p>
<blockquote><p>
server {<br />
listen       80;<br />
server_name  yourmublogs.com *.yourmublogs.com;</p>
<p>location ~* ^.+\.(html&#124;jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js)$<br />
{<br />
root /home/yourmublogs/public_html;<br />
rewrite ^/.*(/(wp-admin&#124;wp-includes)/.*\.(html&#124;jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js))$ $1 last;<br />
rewrite ^/.*(/wp-content/(themes&#124;plugins&#124;mu-plugins)/.*\.(html&#124;jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js))$ $1 last;<br />
rewrite ^.*/files/(.*(html&#124;jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js))$ /wp-content/blogs.php?file=$1 last;</p>
<p>rewrite ^.*/files/(.*(html&#124;jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js))$ /wp-content/blogs.php?file=$1 last;<br />
expires 10d;<br />
break;<br />
}</p>
<p>location / {<br />
root   /home/yourmublogs/public_html;<br />
index  index.html index.htm index.php;</p>
<p>if (!-e $request_filename) {<br />
rewrite ^.+?(/wp-.*) $1 last;<br />
rewrite ^.+?(/.*\.php)$ $1 last;<br />
}</p>
<p>if ($http_cookie !~* "comment_author_&#124;wordpress&#124;wp-postpass_" ) {<br />
rewrite ^(.*)$ /wp-content/cache/supercache/$http_host/$1index.html;<br />
break;<br />
}</p>
<p>error_page    404  =  @tricky;<br />
}</p>
<p>location @tricky {<br />
rewrite ^ /index.php last;<br />
rewrite ^/.*(/wp-login.php)$ $1;<br />
rewrite ^/.*(/wp-admin/.*\.php)$ $1;<br />
rewrite ^/.*(/wp-includes/.*\.php)$ $1;<br />
fastcgi_pass   127.0.0.1:8084;<br />
fastcgi_index  index.php;<br />
fastcgi_param  SCRIPT_FILENAME /home/yourmublogs/public_html$fastcgi_script_name;<br />
include /usr/local/nginx/conf/fastcgi_params;<br />
}</p>
<p>error_page   500 502 503 504  /50x.html;<br />
location = /50x.html {<br />
root   html;<br />
}<br />
}</p>
<p>server {<br />
server_name www.yourmublogs.com;<br />
rewrite ^/(.*) http://yourmublogs.com/$1 permanent;<br />
}</p>
</blockquote>
<p>Ajax could be used for commenting.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Multiple FastCgi PHP Servers Nginx Load Balancing]]></title>
<link>http://bookmarks.honewatson.com/2008/04/24/multiple-fastcgi-php-servers-nginx-load-balancing/</link>
<pubDate>Thu, 24 Apr 2008 01:16:43 +0000</pubDate>
<dc:creator>honewatson</dc:creator>
<guid>http://bookmarks.honewatson.com/2008/04/24/multiple-fastcgi-php-servers-nginx-load-balancing/</guid>
<description><![CDATA[Update: Do not use this config for php.  Instead use php-fpm with xcache.
To configure Nginx to loa]]></description>
<content:encoded><![CDATA[<p><strong><em>Update: </em></strong>Do not use this config for php.  Instead use php-fpm with xcache.</p>
<p>To configure Nginx to load balance multiple FastCgi servers use this type of configuration:</p>
<blockquote><p>upstream servercom {<br />
server 127.0.0.1:44440;<br />
server 127.0.0.1:44441;<br />
server 127.0.0.1:44442;<br />
server 127.0.0.1:44443;<br />
server 127.0.0.1:44444;<br />
}</p>
<p>location ~ \.php$ {<br />
fastcgi_pass servercom;<br />
fastcgi_index stream.app;<br />
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;<br />
include /etc/nginx/fastcgi.conf;<br />
}</p></blockquote>
<p><!--more--></p>
<p>If you're using spawn-fcgi from lighttpd consider replacing it with <a href="http://php-fpm.anight.org/docs.html">php-fpm</a>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Open source software at Smarkets]]></title>
<link>http://smarkets.wordpress.com/?p=19</link>
<pubDate>Wed, 23 Apr 2008 11:29:59 +0000</pubDate>
<dc:creator>Hunter Morris</dc:creator>
<guid>http://smarkets.wordpress.com/?p=19</guid>
<description><![CDATA[I&#8217;m an unabashed open source fanboy.  At Smarkets, I use a lot of software written by other pe]]></description>
<content:encoded><![CDATA[<p>I'm an unabashed open source fanboy.  At Smarkets, I use a lot of software written by other people.  Here is a quick summary of the Smarkets stack; think of them as geek shoutouts.</p>
<ul>
<li><a href="http://www.erlang.org/">Erlang</a> - Almost everything is built atop the Erlang/OTP application system. I like <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a>. It is easier to manage complexity in a language with reasonably isolated <a href="http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29">side effects</a>. Erlang's <a href="http://en.wikipedia.org/wiki/Concurrency_%28computer_science%29">concurrency</a> primitives have been touted many times before, and conceptualising concurrent systems as communicating sequential processes now feels a lot more natural than other paradigms. As Damien Katz <a href="http://damienkatz.net/2008/04/lisp_as_blub.html">recently mentioned</a>, systems built atop Erlang/OTP don't seem to suffer the same failures under high load as certain other garbage collected languages do.</li>
<li><a href="http://code.google.com/p/distel/">Distel</a> on <a href="http://www.gnu.org/software/emacs/">Emacs</a> - When writing code (and actually quite a bit more), I like Emacs. When writing Erlang, I like Distel. It provides a natural entry point for debugging pieces of Erlang code. Getting Emacs to communicate with an inferior Erlang VM is especially useful for rapid prototyping. Being able to do everything within Emacs is good for productivity.</li>
<li><a href="http://www.erlang.org/doc/apps/mnesia/index.html">Mnesia</a> - Arbitrary term storage is a simple way to avoid having to interface with another database management system. Because Mnesia is part of Erlang/OTP, you get it for free.</li>
<li><a href="http://code.google.com/p/mochiweb/">Mochiweb</a> and <a href="http://nginx.net/">nginx</a> - Thanks to <a href="http://bob.pythonmac.org/">Bob Ippolito</a> and Matthew Dempsky (and others I'm sure I've missed) for the mochiweb HTTP toolkit. It's lightweight and embeddable, so it was very easy for us to integrate with our backend. Nginx performs well and is very simple to integrate with a backend powered by mochiweb.</li>
<li><a href="http://code.google.com/p/sgte/">sgte</a> and <a href="http://www.stringtemplate.org/">StringTemplate</a> - <a href="http://blog.sgconsulting.it/">Filippo Pacini's</a> sgte template engine ("inspired by" StringTemplate) was the basis for our templating system.</li>
<li><a href="http://www.stacken.kth.se/project/yxa/">YXA</a> - While we don't specifically deploy any SIP software, YXA is a great example of well-written Erlang. I learned a lot from reading through Magnus Ahltorp and Fredrik Thulin's code. It's been around for several years and has matured quite a bit as a result.</li>
<li><a href="http://en.wikipedia.org/wiki/Flat_file">Flat files</a> - Writing a binary file to disk is sometimes overlooked as a solid way to persist sequential data that's only needed locally. I'm not sure who I should thank here, but I think the list would probably be pretty long.</li>
</ul>
]]></content:encoded>
</item>

</channel>
</rss>
