Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Debian based host and using Nginx and PHP-FPM, I wants to enable user directories in nginx and wants multiuser support with basic authentication also. That means when Alex open; That will prompt for login and password and after authentication, This should point to his own version of php script located at /home/alex/www/rutorrent and when Bob will open;That will prompt for login and password and after authentication This should point to his php script located at /home/bob/www/rutorrent.

I already tried the official documentation located here:

But i am not sure how configure them into default file so that i can get my desired functionality, My default config file of nginx is here:

server {
    server_name localhost;

    location / {
          try_files $uri $uri/ /index.html;

    location /doc/ {
           alias /usr/share/doc/;
           autoindex on;
           allow ::1;
           deny all;

     index index.php index.html index.htm;
     location ~ ^/~([^/]*)(.*)\.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            auth_basic "Restricted";
            auth_basic_user_file /etc/nginx/sites-available/.htpasswd;
            fastcgi_param SCRIPT_FILENAME /home/$1/www$2.php;
            include fastcgi_params;


     location ~ ^/~([^/]*)(.*) {
            autoindex on;
            alias /home/$1/www$2;
            auth_basic "Restricted";
            auth_basic_user_file /etc/nginx/sites-available/.htpasswd;

      location /RPC2 {
            include scgi_params;
            scgi_pass localhost:5000;


Is there any way to get this?

share|improve this question
up vote 3 down vote accepted

Thanks to help me, I got clue to fix User Directories issue, I am using $remote_user variable in main nginx config file, Nginx capture user name in $remote_user variable while we use basic authentication, So very nice and easy way to use User Directories if we include like in this way:

share|improve this answer
Hmm... Thanks! I didn't know about it. – Ali Hashemi Oct 8 '13 at 4:27

You can't do this using nginx config file. You'd better use a php script connected to database for authentication and then use a redirect.

share|improve this answer
thanks, can you explain in more better way? – Pradeep Gupta Oct 6 '13 at 6:02
you have database table of user/pass which you connect to it for authentication using a php script. According to the username provided you decide where to redirect the user inside the php script. – Ali Hashemi Oct 6 '13 at 6:12
At present i am using simple authentication so no any database i am using now, i simple created authentication file and refer its location in config file, Now how to do that and how to redirect? is there any online documentation which i can refer? – Pradeep Gupta Oct 6 '13 at 6:19
You cannot do redirection based on basic authentication you add to config file. This is why you have to use another method to do proper redirections. Without redirection you can simply continue with basic authentication though. – Ali Hashemi Oct 6 '13 at 8:19
I mean that, Is there any online documentation or link where i can read about this redirection and all of stuff which you are referring? – Pradeep Gupta Oct 6 '13 at 8:34

Your Answer


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.