server {
listen 8080 default_server;
listen [::]:8080 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name <domain.com>;
location / {
try_files $uri $uri/ =404;
}
# option 1
location /data {
root /var/www/;
autoindex on;
}
# option 2
location /static {
alias /var/www/data/;
autoindex on;
}
# option 3
location ~ ^/(images|css|js) {
root /var/www/data/;
autoindex on;
}
}
Put some files under /data/static
Access http://domain.com/static/<filename>
Access http://domain.com/images/<image filename>
There is a difference between root
and alias
.
The path in location will be concatenated to the root.
location will not be concatenated to root, but using location directly.