nginx 日志按日期分隔

 

 

#user  nobody;

user root;
worker_processes  1;


error_log  /spdblogs/nginx/logs/error.log;
error_log  /spdblogs/nginx/logs/notice.log  notice;
error_log  /spdblogs/nginx/logs/info.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    proxy_headers_hash_max_size 51200;
    proxy_headers_hash_bucket_size 6400;
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 10m;

    map $time_iso8601 $logdate {
        '~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
        default    'date-not-found';
    }
    #过滤lua循环的日志
    map $http_user_agent $normal {
        ~^lua-resty-http  0;
        default 1;
    }

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                 '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    log_format  main '{"@timestamp":"$time_iso8601",'
                           '"host":"$server_addr",'
                           '"clientip":"$remote_addr",'
                           '"size":$body_bytes_sent,'
                           '"request_time":$request_time,'
                           '"upstreamhost":"$upstream_addr",'
                           '"http_host":"$host",'
                           '"url":"$request_uri",'
                           '"domain":"$host",'
                           '"http_x_forwarded_for":"$http_x_forwarded_for",'
                           '"referer":"$http_referer",'
                           '"http_user_agent":"$http_user_agent",'
                           '"request":"$request",'
                           '"status":"$status"}';


    access_log  /logs/nginx/logs/access-$logdate.log  main if=$normal;
    #error_log  /logs/nginx/logs/error-$2.log;
    #error_log  /logs/nginx/logs/notice-$2.log  notice;
    #error_log  /logs/nginx/logs/info-$2.log  info;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream icar {
    #server 192.168.0.91:9001 max_fails=5;        
    server 192.168.0.81:9001 max_fails=5;
    server 192.168.0.118:9001 max_fails=5;
        
        keepalive 400;
    }

    upstream icarimg {
    server 192.168.0.91:9018;
    server 192.168.0.81:9018;
    }


    server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Headers' '*';
        add_header 'Access-Control-Allow-Methods' '*';
  }
}

 

如果是error的话,就写个定时服务去cp ,然后  /usr/local/nginx/sbin/nginx -s reload  

不然的话就要去修改源码了。

posted @ 2021-09-01 15:57  ☆♂安♀★  阅读(524)  评论(0编辑  收藏  举报