Nginx日志
错误日志增加一行 error_log logs/error.log;
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;
参数变量说明:
nginx.conf配置文件
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
error_log logs/error.log;
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;
sendfile on;
keepalive_timeout 65;
include zj/hello.conf;
include zj/world.conf;
虚拟主机配置文件
添加一行(每个虚拟主机都要加一行):access_log logs/access_www.log main;
后面加上 buffer 和 f;ush选项,提升网站访问性能。
server {
listen 9999;
server_name www.world.com;
location / {
root html/world;
index index.html index.htm;
}
access_log logs/access_www.log main gzip buffer=32k flush=5s;
}
日志轮询切割-切割脚本
#!/bin/sh
Dateformat=`date +%Y%m%d`
Basedir="/appliction/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1
[ -f ${Logname}.log ]|| exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
$Basedir/sbin/nginx -s reload
定时任务,每天00点执行脚本
脚本名:nginx_log.sh 存放目录:/mnt/script/nginx_log.sh
cat >>/var/spool/cron/root << EOF
00 00 * * * /bin/sh /mnt/script/nginx_log.sh >/dev/null 2>&1
EOF