| Syntax: | alias path |
| Default: | |
| Context: | location |
| Reference: | alias |
This directive assigns a path to be used as the basis for serving requests for the indicated location. Note that it may look similar to the root directive at first sight, but the document root doesn't change, just the file system path used for the request. The location part of the request is dropped in the request Nginx issues. Let's see this in action. Consider the following example.
A request for "/i/top.gif" will instruct Nginx to serve the file "/spool/w3/images/top.gif". As you can see, only the part of the URI after the location is appended. The location itself, in this case "/i/", is dropped. With a root directive the full path is appended, i.e., in the above example it would have been, "/spool/w3/images/i/top.gif" — hence including also the location "/i/".
Aliases can also be used in a location specified by a regex.
For example:
The request "/download/book.pdf" will return the file "/home/website/files/book.pdf". Note again that only part of the request URI after the location is appended to the path defined by alias.
It is possible to use variables in the replacement path.
Note that there is a longstanding bug that alias and try_files don't work together.