server {
....
location = /url/to/js/file/script.js {
root /path/to/directory/with/static/files/;
expires 30d;
try_files $uri $uri/ =404;
error_page 404 /404.html;
}
location = /url/to/css/file/style.js {
root /path/to/directory/with/static/files/;
expires 30d;
try_files $uri $uri/ =404;
error_page 404 /404.html;
}
...
}
/path/to/directory/with/static/files/script.js
- а веб-сервер ищет его в /path/to/directory/with/static/files/url/to/js/file/script.js
. Почитайте про префиксные локейшены и директиву alias. location = /url/to/js/file/first-script.js {
alias /path/to/directory/with/static/files/first-script.js;
expires 30d;
try_files $uri $uri/ =404;
error_page 404 /404.html;
}
location = /url/to/css/file/style.css {
alias /path/to/directory/with/static/files/style.css;
expires 30d;
try_files $uri $uri/ =404;
error_page 404 /404.html;
}
location = /url/to/js/file/second-script.js {
alias /path/to/directory/with/static/files/second-script.js;
expires 30d;
try_files $uri $uri/ =404;
error_page 404 /404.html;
}