有关日志的选项如下 :
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