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?