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

一、Nginx访问日志

日志格式

  vim /usr/local/nginx/conf/nginx.conf          //搜索log_format

combined_realip //规则名字

  • 除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加
vim /usr/local/nginx/conf/vhost/test.com.conf

添加  access_log /tmp/1.log combined_realip;
  • 这里的combined_realip就是在nginx.conf中定义的日志格式名字

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
 curl -x127.0.0.1:80 test.com -I
 cat /tmp/1.log

二、Nginx日志切割

  • 自定义shell 脚本
 vim /usr/local/sbin/nginx_log_rotate.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`    //for后面的log是一个变量名,
do
    mv $log $log-$d
done
/bin/kill -HUP `cat $nginx_pid`

  • 任务计划
 crontab -e

添加

 0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh  //每天零点切割日志

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

vim /usr/local/nginx/conf/vhost/test.com.conf

添加配置如下

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

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
echo  "good good study" > /data/wwwroot/test.com/1.jpg
echo  "day day up" > /data/wwwroot/test.com/666.css
curl -x127.0.0.1:80 test.com/1.jpg
curl -x127.0.0.1:80 test.com/666.css
curl -x127.0.0.1:80 test.com/index.html
cat /tmp/1.log

//jpg文件和css文件的访问没有记录log

原文地址:http://blog.51cto.com/13569831/2107916

时间: 2024-08-04 01:32:35

48.Nginx访问日志、Nginx日志切割、静态文件不记录日志和过期时间的相关文章

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

一.Nginx访问日志#vim /usr/local/nginx/conf/nginx.conf日志格式的名字combined_realip可以自定义,例如将它修改为aming,注意,这里定义为什么,后面引用的时候就定义为什么(nginx配置文件看见分号才是这一行结束)#vim /usr/local/nginx/conf/vhost/test.com.conf //增加如下一行#/usr/local/nginx/sbin/nginx -t#/usr/local/nginx/sbin/nginx

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

Nginx访问日志 1. 进入配置文件 [[email protected] src]# vim /usr/local/nginx/conf/nginx.conf  //搜索log_format 参考更改配置成如下: log_format aming '$remote_addr $http_x_forwarded_for [$time_local]' 如图: 日志格式字段含义如下: combined_realip为日志格式的名字,后面可以调用它. 2.到虚拟主机配置文件中指定访问日志的路径 [[

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

Nginx的访问日志 Nginx的日志切割 Nginx静态文件不记录日志和过期时间 原文地址:http://blog.51cto.com/13515599/2086909

十二周三课 Nginx访问日志、 Nginx日志切割、 静态文件不记录日志和过期时间

Nginx访问日志 Nginx的文件格式存在于主配置文件中./usr/local/nginx/conf/nginx.conf然后搜索log_format找到他的配置文件这样我们就可以进行日志的格式配置了. 我们常用如下配置.$remote_addr客户端IP(公网IP)$http_x_forwarded_for代理服务器的IP$time_local服务器本地时间$host访问主机名(域名)$request_uri访问的url地址$status状态码$http_refererreferer$htt

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

一.Nginx访问日志 日志格式 # pwd /usr/local/nginx/conf [[email protected] conf]# vim nginx.conf log_format ELA '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"'; 解析

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

Nginx访问日志 Nginx访问日志主要有两个参数控制:log_format #用来定义记录日志的格式(可以定义多种日志格式,取不同名字即可)access_log #用来指定日至文件的路径及使用的何种日志格式记录日志 设置访问日志的格式,打开配置文件vim /usr/local/nginx/conf/nginx.conf 搜索关键字log_format就可以找到日志格式配置行log_format语法格式及参数语法说明如下:$remote_addr客户端IP(公网IP)$http_x_forwa

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

1.Nginx访问日志 配制访问日志:默认定义格式: log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' ' $host "$request_uri" $status' ' "$http_referer" "$http_user_agent"';  (这是定义日志引用时的名字:combined_realip,后面的内容,就是需要被引用的)可以理

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

一:nginx访问日志 日志格式vim /usr/local/nginx/conf/nginx.conf //搜索log_format$remote_addr 客户端ip(公网ip)$http_x_forwarded_for 代理服务器的ip$time_local 服务器本地时间$host 访问主机名(域名)$request_uri 访问的url地址$status 状态码$http_referer referer$http_user_agent user_agent除了在主配置文件nginx.c

LNMP(3) 静态文件不记录日志和过期时间、Nginx防盗链、Nginx访问控制、解析php

                    静态文件不记录日志和过期时间 进入到虚拟主机配置文件 cd /usr/local/nginx/conf/vhost  编辑虚拟主机配置文件:vim test.com.conf  添加内容:   配置如下 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires      7d;    //过期时间 access_log off; } location ~ .*\.(js|css)$ { expires