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
You may also want to read these posts:
- Nginx, Simple Http Authentication Using ngx_http_auth_pam_module Module
- Nginx Memcached Module, Caching Webiste Image Using Memcached
- Nginx, Strip All Newlines Using nginx-nonewlines Module
- Nginx Blocking Spoofed Google Bot
- Nginx – Customizing 404 page
- Nginx Configuration SyntaxHighlighting
- Nginx As Reverse Proxy IPV6 to IPV4 Website
- Nginx Reverse Proxying Multiple Domains Using map Module
- How To Graph Nginx Statistics
- Nginx Memcached module And PHP
Follow me on Twitter