@bornkiller
2018-07-18T16:12:46.000000Z
字数 995
阅读 1202
前端运维
服务器上 nginx
可能输出大量日志,随着访问量增大,单文件会越来越大,影响读写性能,需要作日志切分,定时脚本可以完成,但是推荐使用系统自带 logrotate
来处理,避免引入过多自定义脚本。
主要操作涉及如下文件:
/etc/logrotate.conf
/etc/logrotate.d/
/var/log/*.log {
daily
rotate 7
missingok
dateext
notifempty
compress
delaycompress
sharedscripts
postrotate
[ -e /usr/local/nginx/logs/nginx.pid ] && kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
endscript
}
# 反向代理标准头
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# 默认日志格式
log_format combined '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# 改良日志格式,输出 IP 实际地址
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
# 运行状态采集 metricbeat
location /server-status {
allow 127.0.0.1;
deny all;
stub_status on;
access_log off;
}