H5游戏如何配置Nginx缓存但是index文件不缓存

expires max 表示最长过期时间,即一直缓存。

expires -1 表示立即过期,即不缓存。

按如下配置,使test整个目录可以被客户端浏览器缓存,但是index.html文件不缓存,使版本重新构建后,访问index文件能实时刷新,适用于生成了MD5的h5游戏。

Nginx配置实例如下

server {
    listen       8080;
    server_name  localhost;

    // 缓存test目录
    location / {
        root   /usr/share/nginx/test;
        index  index.html index.html;
        expires max;
        etag off;
        if_modified_since off;
    }
    
    // 但test目录下的index.html不缓存
    location = /index.html {
        root /usr/share/nginx/test;
        expires -1;
    }
}
发布了133 篇原创文章 · 获赞 63 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/foupwang/article/details/104351333