码迷,mamicode.com
首页 > 其他好文 > 详细

nginx-日志

时间:2018-06-12 19:44:42      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:TE   定时任务   cti   event   div   9.png   文件   .sh   main   

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

 

nginx-日志

标签:TE   定时任务   cti   event   div   9.png   文件   .sh   main   

原文地址:https://www.cnblogs.com/hulue/p/9174478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!