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

12.10 Nginx访问日志

[[email protected] vhost]# vim test.com.conf
除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加
access_log /tmp/test.com.log martin;
这里的combined_realip就是在nginx.conf中定义的日志格式名字

[[email protected] 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
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] vhost]# curl -x127.0.0.1:80 test.com -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Wed, 14 Mar 2018 15:39:14 GMT
Content-Type: text/html
Content-Length: 9
Last-Modified: Tue, 13 Mar 2018 16:20:55 GMT
Connection: keep-alive
ETag: "5aa7fa67-9"
Accept-Ranges: bytes

[[email protected] vhost]# cat /tmp/test.com.log
127.0.0.1 - [14/Mar/2018:23:34:33 +0800] test2.com "/admin/index.html" 301 "-" "curl/7.29.0"
127.0.0.1 - [14/Mar/2018:23:39:14 +0800] test.com "/" 200 "-" "curl/7.29.0"

12.11 Nginx日志切割

[[email protected] vhost]# 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
do
mv $log $log-$d
done
/bin/kill -HUP `cat $nginx_pid

[[email protected] vhost]# ls /usr/local/nginx/logs/nginx.pid
/usr/local/nginx/logs/nginx.pid

[[email protected] vhost]# ls /tmp/
mysql.sock
pear
php-fcgi.sock
systemd-private-d3d5de9693ed4f8ebbf3d1f91826a8cd-chronyd.service-zjb45v
systemd-private-d3d5de9693ed4f8ebbf3d1f91826a8cd-vgauthd.service-evgZ7p
systemd-private-d3d5de9693ed4f8ebbf3d1f91826a8cd-vmtoolsd.service-twe9Yk
test.com.log
test.com.log-20180313

[[email protected] vhost]# crontab -e
no crontab for root - using an empty one

任务计划 crontab -e
0 0 * /bin/bash /usr/local/sbin/nginx_log_rotate.sh

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

[[email protected] vhost]# cat test.com.conf
server
{
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;
}
access_log /tmp/test.com.log martin;
location ~ .
.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 7d;
access_log off;
}
location ~ .*.(js|css)$
{
expires 12h;
access_log off;
}

}

[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] 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
[[email protected] vhost]# cd /data/wwwroot/test.com/
[[email protected] test.com]# ls
index.html
[[email protected] test.com]# vim 1.gif
[[email protected] test.com]# vim 2.js
[[email protected] test.com]# curl -x127.0.0.1:80 test.com/1.gif
dfgsdfgsdfgsdfg
[[email protected] test.com]# curl -x127.0.0.1:80 test.com/2.js
dfasdfasdfasdf
[[email protected] test.com]# curl -x127.0.0.1:80 test.com/index.html
test.com
[[email protected] test.com]# cat /tmp/test.com.log
127.0.0.1 - [15/Mar/2018:00:19:27 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
[[email protected] test.com]# curl -x127.0.0.1:80 test.com/index.html
test.com
[[email protected] test.com]# cat /tmp/test.com.log
127.0.0.1 - [15/Mar/2018:00:19:27 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [15/Mar/2018:00:20:51 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
[[email protected] test.com]# curl -x127.0.0.1:80 test.com/2.jsghfgfh
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
[[email protected] test.com]# curl -x127.0.0.1:80 test.com/2.js -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Wed, 14 Mar 2018 16:21:27 GMT
Content-Type: application/javascript
Content-Length: 15
Last-Modified: Wed, 14 Mar 2018 16:18:11 GMT
Connection: keep-alive
ETag: "5aa94b43-f"
Expires: Thu, 15 Mar 2018 04:21:27 GMT
Cache-Control: max-age=43200
Accept-Ranges: bytes

[[email protected] test.com]# cat /tmp/test.com.log
127.0.0.1 - [15/Mar/2018:00:19:27 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [15/Mar/2018:00:20:51 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [15/Mar/2018:00:21:03 +0800] test.com "/2.jsghfgfh" 404 "-" "curl/7.29.0"

原文地址:http://blog.51cto.com/12058686/2086994

时间: 2024-10-24 12:40:56

12.10 Nginx访问日志 12.11 Nginx日志切割 12.12 静态文件不记录日志和过期的相关文章

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

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

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

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.

十二周三课 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访问日志#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日志切割、静态文件不记录日志和过期时间

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