Nginx And Unix User Directories

As mentioned in the nginx wiki webiste, Nginx does not natively support user dirs, but as of 0.7.42 it can be done by using regex captures. i’ve tested it using this simple configuration.

server {
                listen       192.168.200.18:80;
                server_name  _;
                access_log  /var/log/nginx/nginx-userdirs-access.log  main;

                location ~ ^/~(.+?)(/.*)?$ {
                        alias /home/$1/public_html$2;
                }
}

explaination:

location ~ ^/~(.+?)(/.*)?$ {

~		= tilde
(.+?)	= homedir
(/.*)	= request file / rest of uri

alias /home/$1/public_html$2;

$1	= variable subtitution for homedir
$2	= variable subtitution for requested file or uri

The requested url would be like this:

http://www.example.com/~user/test.html

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *