User Home Directories in Nginx, Part 3

I recently upgraded to the newest version of Nginx, and discovered that the technique I described in my previous two posts no longer works. The good news is that it no longer works because some of the bugs in Nginx were fixed, and the reason I needed that complicated workaround solution was because of bugs in Nginx.

Now, the configuration file is much simpler:

    index index.php index.html index.htm;
    location ~ ^/~([^/]*)(.*)\.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass localhost:9000;
        fastcgi_param SCRIPT_FILENAME /home/$1/public_html$2.php;
    }
location ~ ^/~([^/]*)(.*) {
    autoindex on;
    alias /home/$1/public_html$2;
}</pre></blockquote>

The index line includes index.php to allow for script index files. The first location block deals with PHP files and the second deals with regular files. The key to both of them is the regular expression in the location lines: the first block of parentheses captures the user name, and the second block captures everything after it.