Root and Alias Directives
1 min read
- Authors
- Name
- Vijaykumar Rajendran
- @vijayrajendran_

Table of Contents
Root and Alias Directives
Root Directive
Use root for your main content directory. It appends the request path to the root.
server {
root /var/www/example;
location / {
# /file.html maps to /var/www/example/file.html
}
}
Alias Directive
Use alias for special paths. It replaces the location path with the specified directory.
server {
location /downloads/ {
alias /mnt/storage/files/;
# /downloads/file.zip → /mnt/storage/files/file.zip
}
}
Key Differences
| Feature | Root | Alias |
|---|---|---|
| Path behavior | Appends | Replaces |
| Use case | General content | Special paths |
| Performance | Better | Good |
Practical Example
server {
root /var/www/example;
location / {
try_files $uri =404;
}
location /media/ {
alias /var/media/uploads/;
}
}
Choose wisely based on your needs!