The simplest solution is where you have total control over the filesystem and URI name spaces, so that the application in /path/to/root/foo/index.html
is accessible using the URI /foo/
and the application in /path/to/root/bar/index.html
is accessible using the URI /bar/
.
In this case, no location
blocks are necessary, and the value of root
is /path/to/root
because the pathname of the file is constructed by concatenating this value with the URI. See this document for details.
For example:
server {
server_name example.com;
root /path/to/root;
}
The above server block will fine application foo at http://example.com/foo/
and application bar at http://example.com/bar/
.
In the case where the top level directory element has a different name to the top level URI element, you will need to use an alias
directive within a location
block. See this document for details.
For example:
server {
server_name example.com;
location /foo/ {
alias /path/to/foos/directory/;
}
location /bar/ {
alias /path/to/bars/directory/;
}
}
Both the location
value and the alias
value should end with /
, or neither end with /
.
Note that the location
directive is used without the =
operator, which is only used to match a single URI. See this document for details.
CLICK HERE to find out more related problems solutions.