nginx-日志

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

 

转载于:https://www.cnblogs.com/hulue/p/9174478.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值