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

11月27日任务

12.10 Nginx访问日志

12.11 Nginx日志切割

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

12.10 Nginx访问日志

  • 除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加
  • access_log /tmp/1.log combined_realip;
  • 这里的combined_realip就是在nginx.conf中定义的日志格式名字
  • -t && -s reload
  • curl -x127.0.0.1:80 test.com -I
  • cat /tmp/1.log

[root@zgxlinux-01 vhost]# vim ../nginx.conf         #修改日志名称

[root@zgxlinux-01 vhost]# vim test.com.conf

[root@zgxlinux-01 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@zgxlinux-01 vhost]# /usr/local/nginx/sbin/nginx -s reload

[root@zgxlinux-01 vhost]# curl -x127.0.0.1:80 test4.com/admin/index.html/asdkfh -I
HTTP/1.1 404 Not Found
Server: nginx/1.14.0
Date: Sat, 01 Dec 2018 03:20:47 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

[root@zgxlinux-01 vhost]# curl -x127.0.0.1:80 test3.com/admin/index.html/asdkfh -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0
Date: Sat, 01 Dec 2018 03:20:54 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/admin/index.html/asdkfh

[root@zgxlinux-01 vhost]# curl -x127.0.0.1:80 test2.com/admin/index.html/asdkfh -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0
Date: Sat, 01 Dec 2018 03:21:08 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/admin/index.html/asdkfh

[root@zgxlinux-01 vhost]# cat /tmp/test.com.log 
127.0.0.1 - [01/Dec/2018:11:20:54 +0800] test3.com "/admin/index.html/asdkfh" 301 "-" "curl/7.29.0"
127.0.0.1 - [01/Dec/2018:11:21:08 +0800] test2.com "/admin/index.html/asdkfh" 301 "-" "curl/7.29.0"

12.11 、Nginx日志切割

  • 自定义shell 脚本
  • vim /usr/local/sbin/nginx_log_rotate.sh//写入如下内容

#! /bin/bash
## 假设nginx的日志存放路径为/data/logs/
d=`date -d "-1 day" +%Y%m%d` 
logdir="/data/logs"
nginx_pid="/usr/local/nginx/logs/nginx.pid"
cd $logdir
for log in `ls *.log`
do
    mv $log $log-$d
done
/bin/kill -HUP `cat $nginx_pid`

  • 任务计划
  • 0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh

#操作过程

[root@zgxlinux-01 vhost]# vim /usr/local/sbin/nginx_logrotate.sh

[root@zgxlinux-01 vhost]# sh -x  /usr/local/sbin/nginx_logrotate.sh       #执行这个脚本,-x表示查看执行过程
++ date -d '-1 day' +%Y%m%d
+ d=20181130
+ logdir=/tmp/
+ nginx_pid=/usr/local/nginx/logs/nginx.pid
+ cd /tmp/
++ ls test.com.log
+ for log in '`ls *.log`'
+ mv test.com.log test.com.log-20181130
++ cat /usr/local/nginx/logs/nginx.pid
+ /bin/kill -HUP 4421
[root@zgxlinux-01 vhost]# ls /tmp/
mysql.sock
pear
php-fcgi.sock
systemd-private-bbc1c842e4c14aefa0295c2d1c669add-chronyd.service-yevkTQ
test.com.log
test.com.log-20181130
[root@zgxlinux-01 vhost]# find /tmp/ -name *.log-* -type f -mtime +30 |xargs rm   #长时间以后需要清理日志,xargs进行删除操作。
rm: 缺少操作数
Try 'rm --help' for more information.

[root@zgxlinux-01 vhost]# find /tmp/ -name *.log-* -type f 
/tmp/test.com.log-20181130
[root@zgxlinux-01 vhost]# find /tmp/ -name *.log-* -type f |xargs rm -rf
[root@zgxlinux-01 vhost]# find /tmp/ -name *.log-* -type f 
[root@zgxlinux-01 vhost]# ls /tmp/
mysql.sock
pear
php-fcgi.sock
systemd-private-bbc1c842e4c14aefa0295c2d1c669add-chronyd.service-yevkTQ
test.com.log
[root@zgxlinux-01 vhost]# ls /usr/local/sbin/
iptables.sh  nginx_logrotate.sh
[root@zgxlinux-01 vhost]# cat !$/nginx_logrotate.sh
cat /usr/local/sbin//nginx_logrotate.sh
#! /bin/bash
d=`date -d "-1 day" +%Y%m%d` 
logdir="/tmp/"
nginx_pid="/usr/local/nginx/logs/nginx.pid"
cd $logdir
for log in `ls *.log`
do
    mv $log $log-$d
done
/bin/kill -HUP `cat $nginx_pid`

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

  • 配置如下

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

#操作过程

[root@zgxlinux-01 vhost]# vim test.com.conf 

[root@zgxlinux-01 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@zgxlinux-01 vhost]# /usr/local/nginx/sbin/nginx -s reload
[root@zgxlinux-01 vhost]# cd /data/wwwroot/test.com/
[root@zgxlinux-01 test.com]# ls
admin  index.html
[root@zgxlinux-01 test.com]# vim 1.gif
[root@zgxlinux-01 test.com]# vim 2.js

[root@zgxlinux-01 test.com]# curl -x127.0.0.1:80 test.com/1.gif
kdhfkadshfkashkdh
[root@zgxlinux-01 test.com]# curl -x127.0.0.1:80 test.com/2.js
akdksfalsdjflajdfns,shvawekhfkl
[root@zgxlinux-01 test.com]# curl -x127.0.0.1:80 test.com/index.html
test.com
[root@zgxlinux-01 test.com]# cat /tmp/test.com.log 
127.0.0.1 - [01/Dec/2018:12:07:37 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
[root@zgxlinux-01 test.com]# curl -x127.0.0.1:80 test.com/2.jsdsfdss
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

转载于:https://my.oschina.net/u/3959708/blog/2965084

Nginx访问日志、日志切割、静态文件不记录日志和过期时间相关推荐

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

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

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

    2019独角兽企业重金招聘Python工程师标准>>> 静态文件不记录日志和过期时间目录概要 配置如下 location ~ .*\.(gif|jpg|jpeg|png|bmp|sw ...

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

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

  4. Linux centos7 VMware Apache访问日志不记录静态文件、访问日志切割、静态元素过期时间...

    一.Apache访问日志不记录静态文件 网站大多元素为静态文件,如图片.css.js等,这些元素可以不用记录 vim /usr/local/apache2.4/conf/extra/httpd-vho ...

  5. 访问日志不记录静态文件、访问日志切割、静态元素过期时间

    11.22 访问日志不记录静态文件 网站大多元素为静态文件,如图片.css.js等,这些元素可以不用记录 小技巧: 打开浏览器,按键盘上的F12键,开发人员工具,选择Network选项(一般默认),刷 ...

  6. 4.16访问日志不记录静态文件,访问日志切割以及静态元素过期时间

    访问日志不记录静态文件 一个网站会有很多元素,尤其是图片.js.css等静态文件非常多,每个用户请求一个页面都会访问诸多的图片,这些元素都会被记录在日志中,如果一个网站访问量很大,那么这些日志会增长的 ...

  7. 1.8.5 访问日志不记录静态文件

    2019独角兽企业重金招聘Python工程师标准>>> 1.8.5 访问日志不记录静态文件 网站大多元素为静态文件,如图片.css.js等,这些元素可以不用记录 把虚拟主机配置文件改 ...

  8. centos uwsgi配置_centos下配置nginx+uwsgi运行py以及静态文件的加载

    其实不限于centos,个人觉得所有的linux都一样,就好像你喜欢把钱放在左边的口袋,我喜欢把钱放右边的口袋,还有的人喜欢把钱放里面的口袋,无非是配置文件的地方不一样 首先安装nginx,嗯,这个自 ...

  9. 使用nginx缓存服务器上的静态文件

    一.nginx缓存的优点 如图所示,nginx缓存,可以在一定程度上,减少源服务器的处理请求压力. 因为静态文件(比如css,js, 图片)中,很多都是不经常更新的.nginx使用proxy_cach ...

最新文章

  1. 自定义 DataLoader
  2. linux下快速添加Qt的MySQL驱动
  3. securecrt 连接配置存放目录_SecureCRT 迁移到新环境,导出配置文件目录 转(示例代码)...
  4. Linux 网卡信息查看
  5. python文件操作二
  6. tornado的资料(暂时没看)
  7. 不是每个人都适合linux
  8. 前端学习(2875):原生js模块化+入口模块和子类的编写
  9. android notification自动消失,Notification点击事件和点击消失
  10. 配置springcloud配置中心读取github上的配置文件报错:com.jcraft.jsch.JSchException: Auth fail解决方案
  11. 应用程序如何链接静态QT Plugin库
  12. Atitit 动态按钮图片背景颜色与文字组合解决方案
  13. c++ 第五次作业(计算器第三步)
  14. Php sql server2005,phpmssqlserver2005数据库连接类
  15. 在Oracle中查询表的大小、表的占用情况和表空间的大小
  16. 高性价比运维工具推荐
  17. 量子计算机采用量子力学原理,量子计算机的工作是不是就是根据量子力学原理造的?...
  18. 公交车查询系统软件测试,公交APP评测:谁是最好用的公交线路查询软件?
  19. linux条件变量cond,Linux C 条件变量cond的使用记录
  20. 阿尔法编程python答案_C语言程序设计-阿尔法编程(编程答案)

热门文章

  1. 光剑免费图书馆 Free Ebooks
  2. Mysql压测工具mysqlslap 讲解
  3. 演示:动态路由协议RIPv1的配置
  4. 解决svn的working copy locked并且cleanup恢复不能的情况
  5. Web图形开发,SVG还是VML?
  6. 【DB】几种ETL模式
  7. 【观点】“另类”设计模式
  8. spring aop 注入源码解析
  9. mysql--常用基础命令
  10. (C#)Windows Shell 外壳编程系列6 - 执行