linux,  nginx

Nginx 设置浏览器缓存过期时间

根据 nginx 中的 mime 类型有条件地添加过期标头

vim /etc/nginx/nginx.conf
# 在 http{}中配置
map $sent_http_content_type $expires {
    default off;
    text/css 365d;
    application/javascript 365d;
    application/font-woff 365d;
    application/font-woff2 365d;
    application/font-ttf   365d;
    ~font/ 365d;
    ~image/ 365d;
}

expires $expires;

保存配置并退出编辑器,然后重启nginx

systemctl restart nginx

验证过期时间是否生效

留言

您的电子邮箱地址不会被公开。 必填项已用 * 标注