I want the following.
http://some.site/person1/some/path should access /home/person1/some/path
(and http://some.site/person1 accesses /home/person1/index.html
) and http://some.site/person2/some/path should access /home/person2/some/path
(and http://some.site/person2 accesses /home/person2/index.html
). There will be many personX
es. It's important to use a regular expression to tell nginx where to find everything.
I tried coming up with a set of location, root and rewrite directives that would work. The closest I came was this for my sites-available/website
.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /some/default/root;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri.html $uri $uri/ =404;
}
location /person1 {
root /home/person1;
rewrite ^/person1(.*)$ $1 break;
}
}
This does what I want with all paths except for ones of the form http://some.site/person1. In this case, nginx doesn't access /home/person1/index.html
like I want. Instead, the regex returns an empty string which nginx doesn't like (I see complaints in the nginx/error.log).