Disable caching of a single file with try_files directive

后端 未结 6 881
情书的邮戳
情书的邮戳 2021-02-01 16:42

I\'m serving Angular 2 application with nginx using location section this way:

location / {
  try_files $uri $uri/ /index.html =404;
}

try_file

6条回答
  •  眼角桃花
    2021-02-01 17:12

    I got the following setup working for my Angular apps, includes changes to index.html and nginx configuration:

    index.html

    
    
    
    
    
    

    nginx.conf

    location / {
      try_files $uri $uri/ /index.html;
    }
    
    location ~ \.html$ {
      add_header Cache-Control "private, no-cache, no-store, must-revalidate";
      add_header Expires "Sat, 01 Jan 2000 00:00:00 GMT";
      add_header Pragma no-cache;
    }
    

    Works both when user navigates to "site.com" and "site.com/some/url" or "site.com/#/login". The "index.html" changes are to be on the safe side mainly.

提交回复
热议问题