Technology Sharing

  • 首页
  • 资料分享
  • 在线工具
    • 随机密码生成器
  • 介绍
  • RSS
  • privacy
  • 云产品推广
    • 腾讯云
    • 阿里云
Share IT knowledge
  1. 首页
  2. linux
  3. 正文

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

2022年12月5日 240点热度 0人点赞 0条评论

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
vim /etc/nginx/nginx.conf
vim /etc/nginx/nginx.conf
vim /etc/nginx/nginx.conf
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 在 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;
# 在 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;
# 在 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
systemctl restart nginx
systemctl restart nginx
systemctl restart nginx

验证过期时间是否生效

打赏微海报分享
标签: 暂无
最后更新:2022年12月6日

nico

Linux运维工程师 软考网络工程师 && 软考信息安全工程师

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

nico

Linux运维工程师
软考网络工程师 && 软考信息安全工程师

最新 热点 随机
最新 热点 随机
linux部署JDK环境 [Solved] MariaDB import issue: Error at line 1: Unknown command '\-'. Could not retrieve mirrorlist http://mirrorlist.centos.org/ CentOS 7 Kubernetes如何删除卡在“Terminating”状态的命名空间 解决GitLab Runner签名无效 如何禁用 Ubuntu "Daemons using outdated libraries" 弹出窗口
添加虚拟内存swap WordPress修改用户权限(数据库) 搭建tinyproxy代理 Apt安装最新版本的Go语言环境 Nginx反向代理Google MySQL隐藏查询结果并只显示结果的总数
最近评论
woodcockkienzlelsj8o9+73s48g9rr3m0@gmail.com 发布于 11 个月前(07月17日) necessitatibus corporis et odit nam quo harum et c...
RonaldG 发布于 11 个月前(07月07日) Very interesting topic, thank you for putting up.&...
小黑 发布于 1 年前(12月28日) 不错
nico 发布于 2 年前(02月09日) 嘻嘻嘻!!!
Bruse 发布于 2 年前(02月09日) 我来啦!!!
nico 发布于 3 年前(12月10日) 方便查询
Justin 发布于 3 年前(12月10日) 写的很好,谢谢分享!我 Mark 一下~
nico 发布于 3 年前(11月18日) 主题的原因吧
Justin 发布于 3 年前(09月22日) 这篇文章的质量很高呀!写得很详细~ 话说你的文章是隐藏了发布时间吗?
Justin 发布于 3 年前(08月27日) 好家伙,这标题乍一看还以为你打算进军英文技术写作领域了🤓

COPYRIGHT © 2023 Technology Sharing. ALL RIGHTS RESERVED.

备案图标 皖公网安备34132402000202 皖ICP备2023004851号-1