2019独角兽企业重金招聘Python工程师标准>>>

静态文件不记录日志和过期时间目录概要

  • 配置如下
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires      7d;access_log off;}
location ~ .*\.(js|css)${expires      12h;access_log off;}

静态文件不记录日志和过期时间

  • 在配置文件中添加
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$    //匹配gif|jpg|jpeg|png|bmp|swf 后缀的文件{expires      7d;        //7天后过期access_log off;        //匹配“.*.(gif|jpg|jpeg|png|bmp|swf) ”关闭记录日志}
location ~ .*\.(js|css)${expires      12h;        //12个小时后过期access_log off;        //匹配“.*.(js|css) ”关闭记录日志}
  1. 打开虚拟主机配置文件vim /usr/local/nginx/conf/vhost/test.com.conf
[root@hanfeng vhost]# vim /usr/local/nginx/conf/vhost/test.com.confserver
{listen 80;server_name test.com test1.com test2.com;index index.html index.htm index.php;root /data/wwwroot/test.com;if ($host != 'test.com' ) {rewrite  ^/(.*)$  http://test.com/$1  permanent;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires      7d;access_log off;}
location ~ .*\.(js|css)${expires      12h;access_log off;}     access_log /tmp/test.com.log combined_realip;
}
保存退出
  1. 检查配置文件语法错误,并重新加载配置文件
[root@hanfeng vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hanfeng vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@hanfeng vhost]#
  1. 测试,先来模拟一个图片
[root@hanfeng vhost]# cd /data/wwwroot/test.com/
[root@hanfeng test.com]# ls
admin  index.html
[root@hanfeng test.com]# vim 1.gif        在1.gif随意写入一些内容
[root@hanfeng test.com]# vim 2.js
[root@hanfeng test.com]#
  1. 接下来做一个访问测试
[root@hanfeng test.com]# curl -x127.0.0.1:80 test.com/1.gif
sdafasf
[root@hanfeng test.com]# curl -x127.0.0.1:80 test.com/2.js
fghdfsd
[root@hanfeng test.com]# curl -x127.0.0.1:80 test.com/index.html
“test.com”
[root@hanfeng test.com]# 
  1. 查看日志,会看到只有一条日志
[root@hanfeng test.com]# cat /tmp/test.com.log
127.0.0.1 - [05/Jan/2018:00:17:53 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
[root@hanfeng test.com]#
  1. 测试过期时间,加上-I参数
[root@hanfeng test.com]# curl -x127.0.0.1:80 -I test.com/2.js
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 16:22:07 GMT
Content-Type: application/javascript
Content-Length: 8
Last-Modified: Thu, 04 Jan 2018 16:15:42 GMT
Connection: keep-alive
ETag: "5a4e532e-8"
Expires: Fri, 05 Jan 2018 04:22:07 GMT
Cache-Control: max-age=43200
Accept-Ranges: bytes[root@hanfeng test.com]# 
  • max-age=43200 过期时间
  1. 如果去掉expires,则不会显示max-age过期时间

转载于:https://my.oschina.net/u/3707314/blog/1601622

12.12 静态文件不记录日志和过期时间相关推荐

  1. Nginx访问日志、日志切割、静态文件不记录日志和过期时间

    2019独角兽企业重金招聘Python工程师标准>>> 11月27日任务 12.10 Nginx访问日志 12.11 Nginx日志切割 12.12 静态文件不记录日志和过期时间 1 ...

  2. 12.10 Nginx访问日志 12.11 Nginx日志切割 12.12 静态文件不记录日志和过期时间

    - 12.10 Nginx访问日志 - 12.11 Nginx日志切割 - 12.12 静态文件不记录日志和过期时间# 12.10 Nginx访问日志 - 日志的格式- vim /usr/local/ ...

  3. Linux-LNMP(静态元素不记录日志和过期时间,防盗链,解析php,代理,支持ssl)

    Linux-LNMP-Nginx配置二 静态文件不记录日志和过期时间 Nginx防盗链 Nginx访问控制 Nginx解析php相关配置 Nginx代理 Nginx负载均衡 SSL原理 生成SSL密钥 ...

  4. Nginx设置静态页面压缩和缓存过期时间的方法 (转)

    使用nginx服务器的朋友可能都知道需要设置html静态页面缓存与页面压缩与过期时间的设置了,下面我来给各位同学介绍一下配置方法,包括对ico,gif,bmp,jpg,jpeg,swf,js,css, ...

  5. LNMP_静态文件不记录日志,配置缓存

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$         {                 expires      30d;               ...

  6. (五)nginx设置静态文件不记录日志

    一.配置test.com.conf配置文件 添加下面代码 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 7d; access_log off ...

  7. 6月8日任务(12.10 Nginx访问日志 12.11 Nginx日志切割 12.12 静态文件)

    课程名称:12.10 Nginx访问日志 笔记内容: [root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf 定义日志格式 combined_ ...

  8. doraemon的python(大更新) django静态文件的配置(出错多的地方)

    ### 12.2 静态文件的使用#### 12.2.1静态文件的配置和使用 settings.py```python STATIC_URL = '/static/' #别名 STATICFILES_D ...

  9. 4.36域名重定向4.37用户认证4.38Nginx访问日志4.39日志不记录静态文件4.40日志切割...

    2019独角兽企业重金招聘Python工程师标准>>> 域名重定向 用户认证 Nginx访问日志 日志不记录静态文件 日志切割 域名重定向 配置第二个域名: vi /etc/ngin ...

最新文章

  1. Learn OpenGL (六):坐标系统
  2. js添加菜单栏之后停留在那里
  3. 切换卡TabHost控件的使用
  4. 125. Leetcode 91. 解码方法 (动态规划- 字符串系列)
  5. 突破Android微信微博浏览器限制直接拉起应
  6. 为普通Object添加类似AttachedProperty的属性
  7. Java项目几个月能完成_c#项目转JAVA,第5个月,基本完成
  8. DAHDI与Zaptel
  9. Linux网络管理实 验 指 导
  10. 这可能是 Python 面向对象编程的最佳实践
  11. 华为、苹果、谷歌高调宣布要造车!瞄准19万亿美元的智能汽车市场!
  12. 如何实现把固定内容自动写入excel_如何在Excel实现自定义序号的自动设定?
  13. 电脑Bois中usb模式启动热键
  14. E20180404-ts
  15. 2016蓝桥杯java试题_2016年第七届蓝桥杯JavaB组省赛试题解析
  16. 离散数学 习题篇 —— 谓词公式练习
  17. 文本处理及正则表达式
  18. html:运用表单表格制作简易个人简历
  19. 小红书后台开发岗面试经历复盘
  20. 摔手机问题--第九届蓝桥杯

热门文章

  1. mysql基本sql语句总结(一)
  2. oracle重建索引对空间的使用,分析oracle索引空间使用情况,以及索引是否需要重建...
  3. php微信回调验证签名,微信支付回调验证签名处理
  4. echarts y轴只显示5个刻度_ECharts 解决双Y轴刻度不一致问题
  5. macos catalina cdr下载_这个开源神器可快速帮你安装 MacOS 虚拟机
  6. layer checkbox
  7. linux禁ping禁什么端口,Linux配置防火墙,开启80,22等常用端口禁止ping等
  8. mysql5.7 undo_MySQL 5.7新特性之在線收縮undo表空間
  9. Java实现穷举_LeetCode 28:实现strStr() Implement strStr()
  10. 自学c语言后的感受,一路走来,浅谈c语言的学习感想