0

I need some guidance with caching index.html. Right now I have the following directive in my nginx config:

 location / {
    root /usr/share/nginx/html;
    include /etc/nginx/mime.types;
    index index.html;

    # Cache settings
    proxy_cache my_cache;
    proxy_cache_valid 200 10m;
    proxy_cache_valid 404 1m;
    add_header Cache-Control "public, max-age=600, must-revalidate";

    try_files $uri $uri/ /index.html;
}

Suppose my domain is example.com. I noticed that when I make a call to https://example.com the index.html is requested from my server (not cached), but when I do https://example.com/index.html cache is used. How can I cache both?

Next, when I create a new release of my website, I don't want anyone using the old index.html file anymore. In the above example I have an expire time of 10 minutes, but after a release that might be 10 minutes of my site not working anymore. So ideally, only for index.html it would be best that the browser always valides with the server if the cache is still valid (using Etag for example?). What would be the best way to solve this issue?

Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333

0 Answers0