重定向到控制器/操作

I want to be able to convert the following link:

http://domain.com/foo/bar

into http://domain.com/index.php?controller=foo&action=bar

using php5-fpm. I also want to be able to access static files inside www/ folder. How do I do that? This is what I have so far:

server {
    charset utf-8;
    client_max_body_size 8M;

    listen 80; ## listen for ipv4

    server_name domain.com;

    root        /var/www/domain.com/www;
    index       index.php;

    access_log  /var/log/nginx/domain.com.access.log;
    error_log   /var/log/nginx/domain.com.error.log;

    location / {
        rewrite ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /index.php?controller=$1&action=$2;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

But it gives me blank page and no get parameters. How should I do this?

The try_files directive is useful when serving static files, if they exist, and rewriting the URI if they do not. See this document for details.

There are a number of ways to achieve this, for example:

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /index.php?controller=$1&action=$2 last;
    return 404;
}
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
}