Reputation: 301
I have the following configuration to run an angular.js app, which works fine.
location / {
root /usr/share/nginx/html;
index index.html;
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
try_files $uri $uri/ /index.html =404;
}
But when I add cache
location ~* \.(jpg|jpeg|png|gif|swf|svg|ico|mp4|eot|ttf|otf|woff|woff2|css|js)$ {
add_header Cache-Control "max-age=86400, must-revalidate, s-maxage=2592000";
}
The files are not longer accesibles
[error] 5#5: *1 open() "/etc/nginx/html/scripts/vendor-1568b32f3e.js" failed (2: No such file or directory), client: 87.63.75.163, server: localhost, request: "GET /scripts/vendor-1568b32f3e.js HTTP/1.1", host: "myapp", referrer: "http://myapp/auth/login"
Not sure why is trying to get the resources from /etc/nginx/html/
when the root path is /usr/share/nginx/html
Upvotes: 5
Views: 5404
Reputation: 1088
You need to make sure that the "root" defined in the server section matches what you want. Or define "root" under your regex location location ~* \.(jpg|jpeg|png|gif|swf|svg|ico|mp4|eot|ttf|otf|woff|woff2|css|js)$
. Without a root defined there nginx may be reverting to global definition under the server section.
Upvotes: 5