Nginx的日志

有关日志的选项如下 :

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

log_format	定义了日志记录的内容
	$remote_addr			客户端的IP
	$remote_user			客户端的用户
	$time_local				访问时间和时区
	$request				请求的协议
	$status 				状态码
	$body_bytes_sent 		传输给客户端的数据大小
	$http_referer 	 		从哪个页面链接过来的
	$http_user_agent 		浏览器的信息
	$http_x_forwarded_for 	记录客户端的真实地址
172.16.0.20 - - [22/Nov/2019:15:57:22 +0800] "GET / HTTP/1.1" 200 396 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0" "-"

日志轮滚。

rpm包安装的自带轮滚脚本。
不是rpm的手写。

[root@localhost logrotate.d]# vim /etc/logrotate.d/nginx 


/usr/local/nginx/logs/access.log
/usr/local/nginx/logs/error.log
{
        daily
        create
        notifempty
        dateext
        create 0600 root root
        rotate 7
        missingok
        sharedscripts
                postrotate
                /usr/bin/kill -HUP `cat /usr/local/nginx/logs/nginx.pid 2> /dev/null` 2> /dev/null || true
        endscript

}

然后强制轮滚下看看效果。

[root@localhost ~ ]# logrotate -f  /etc/logrotate.d/nginx
[root@localhost nginx]# ls logs/
access.log  access.log-20191125  error.log  error.log-20191125  nginx.pid

这个是日志轮滚说明

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值