How to map authenticated Nginx users to their own directory?
I am writing a social networking site in C and serving it all up with Nginx. How can I make it so that authenticated users go to their own directory -ONLY- where a user-specific index.html resides. I am not asking how to populate the index.html with user specific directives, but how to lock them into their own directory
Solution 1:
map $remote_user $profile_directory {
default $remote_user;
'' guests;
pavel admins;
ivan admins;
}
server {
location /profile/ {
alias /path/to/www/$profile_directory/;
...
}
}
- http://nginx.org/en/docs/http/ngx_http_core_module.html#variables
- http://nginx.org/r/map
- http://nginx.org/r/alias
- http://nginx.org/r/root
- http://nginx.org/r/location
second example (see comments):
server {
location / {
auth_basic "Please Login";
auth_basic_user_file "/etc/nginx/htpasswd";
root /var/www/sites/mysite.com/http/$remote_user;
}
}