May 112011
 

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

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*