Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

configuration for caching static files

$
0
0
I have some problem on configuring Nginx to correctly serve an AngularJS application. The server is configured as follow:

www.example.com we have the landing page of the application
www.example.com/app we have the application itself

the path to the application is the following:

/usr/share/nginx/html/example.com/app/

and static files are inside the following:

/usr/share/nginx/html/example.com/app/public/app/assets

Now I would like to set the caching to "no-cache" for all the html files both in landing page and application but set cache to 60 days to all the js, css and images files.

This is my current nginx server configuration:

server {
listen 80;

index index.html;

server_name example.com www.example.com;

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 60d;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

location ^~ /app {
alias /usr/share/nginx/html/example.com/app/public/;
expires -1;
add_header Pragma "no-cache";
}

location / {
root /usr/share/nginx/html/example.com;
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
}
}

Now the problem is that the location directive:

location ~* \.(?:ico|css|js|gif|jpe?g|png)$

is never executed, so the cache is set as no-cache as defined in the /app directive.

Any idea?

thanks

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>