Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted
map $remote_user $profile_directory {
    default      $remote_user;
    ''           guests;
    pavel        admins;
    ivan         admins;
}

server {

    location /profile/ {
        alias /path/to/www/$profile_directory/;
        ...
    }

}

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;
    }
}
share|improve this answer
    
This looks very interesting. What kind of authentication options could I use with this? I assume that is where the $remote_user gets set, in the authentication module? –  DisgruntledUser Jul 27 '12 at 23:34
    
Yes, it set by nginx.org/en/docs/http/ngx_http_auth_basic_module.html –  VBart Jul 27 '12 at 23:36
    
Thank you so much for your response. I would vote your answer up but I am a new user. –  DisgruntledUser Jul 27 '12 at 23:57
    
I changed your answer only a little bit. Below is my whole bare bones nginx.conf that works as is. I will add back the rest of the configuration later, this is just to show the bare bones example –  DisgruntledUser Aug 9 '12 at 19:13
    
Your "the bare bones example" is very bad. 1. map $remote_user $profile_directory { default $remote_user; } is just NOOP, that wasting CPU and memory. 2. alias /var/www/sites/mysite.com/http/$profile_directory/; is a NOOP too, you should use the root directive instead. –  VBart Aug 27 '12 at 16:37
show 4 more comments
events {
}

http {

  map $remote_user $profile_directory {
    default      $remote_user;
  }
  server {
     root                 /var/www/sites/mysite.com/http;

    location / {
        auth_basic            "Please Login";
        auth_basic_user_file  "/etc/nginx/htpasswd";
        alias /var/www/sites/mysite.com/http/$profile_directory/;
    }
  }
}

This is my edited version, which includes my entire bare bones nginx.conf

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.