0

I am new to Nginx. Now I have a confusion on nginx configurations:

My web site contains folders in different locations:

location / {
  root /Path1;
}

location ^~ /download {
  alias /Path2;
}

When I query http://mysite/download, I am accessing the content of /Path2 instead of /Path1

Now I want to add a sub-directory under download containing my private files, and I want to add password protection. So I add:

location /download/personal {
  auth_basic "Admin Login";
  auth_basic_user_file Path_to_htpasswd;
}

But I got 404 error when querying http://mysite/download/personal after key in my credentials. According to nginx error log, I am directed to /Path1/download/personal, which does not exist. How can I configure nginx, such that all access to http://mysite/download/* will be directed to the same directory in /Path2?

Update:

I may find a solution: just put the sub-directory configuration in the parent conf:

location ^~ /download {
  alias /Path2;
  location /download/personal {
    auth_basic "Admin Login";
    auth_basic_user_file Path_to_htpasswd;
  }
}

Is it correct? Or are there better solutions?

1 Answer 1

0

You already know how to do this. You need to add an alias that points to the correct directory.

3
  • Yes. That is a solution. But then for every subfolder I created I have to make the changes. Is there any solution to configure http://mysite/personal/* all point to /Path2?
    – Starry
    Jun 7, 2014 at 3:15
  • Why do you need to create so many locations? You should more clearly explain what you're trying to accomplish. Jun 7, 2014 at 3:21
  • I have modified my post :) I just want to create a public accessible folder, in which there exists an encrypted subfolder.
    – Starry
    Jun 7, 2014 at 3:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .