使用try_files指令禁用单个文件的缓存 [英] Disable caching of a single file with try_files directive

查看:124
本文介绍了使用try_files指令禁用单个文件的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用定位部分的方式通过nginx为Angular 2应用程序提供服务

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

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

try_files指令尝试在根目录中找到请求的uri,如果找不到它,它只会返回index.html

try_files directive tries to find the requested uri in root directory and if it fails to find one it simply returns index.html

如何禁用index.html文件的缓存?

How to disable caching of index.html file?

推荐答案

使用nginx命名位置找到了解决方案:

Found a solution using nginx named locations:

location / {
    gzip_static on;
    try_files $uri @index;
}

location @index {
    add_header Cache-Control no-cache;
    expires 0;
    try_files /index.html =404;
}

这篇关于使用try_files指令禁用单个文件的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆