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;
    }

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.

Comments 2

  • s can access. Currently there is not any in-memory caching of files, other than optimizations implied by the operating system’s virtual filesystem mechanisms. Each cached response is placed in a different file on the filesystem. The hierarchy (levels and naming details) are controlled through nginx configuration directives. When a response is written to the cache directory structure, the path and the name of the file are derived from an MD5 hash of the proxy URL.

  • may change during request processing, e.g. when doing internal redirects, or when using index files.