Nginx ログフォーマットをLTSV形式に

LINEで送る
Pocket

  • nginx.conf
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid       /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '[nginx]\t'
                    'time:$time_iso8601\t'
                    'server_addr:$server_addr\t'
                    'host:$remote_addr\t'
                    'method:$request_method\t'
                    'reqsize:$request_length\t'
                    'uri:$request_uri\t'
                    'query:$query_string\t'
                    'status:$status\t'
                    'size:$body_bytes_sent\t'
                    'referer:$http_referer\t'
                    'ua:$http_user_agent\t'
                    'forwardedfor:$http_x_forwarded_for\t'
                    'reqtime:$request_time\t'
                    'apptime:$upstream_response_time\t';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    keepalive_timeout 65;

    gzip  on;
    gzip_static on;
    gzip_http_version 1.0;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    open_file_cache max=100000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    proxy_buffer_size 32k;
    proxy_buffers 50 32k;
    proxy_busy_buffers_size 32k;

    include /etc/nginx/conf.d/*.conf;
}
  • log.conf
map $http_user_agent $log_ua {

            ~ELB-HealthChecker 0;

                default 1;
}
  • hoge.com.conf
server {
    listen       80;
    server_name  hoge.com;

    root /var/www/hoge/public;
    index index.php index.html index.htm;

    set_real_ip_from 10.0.0.0/16;
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;

    access_log  /var/log/nginx/access.log main if=$log_ua;
    error_log  /var/log/nginx/error.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
    }
}

 

Was this helpful?

0 / 0

コメントを残す 0

Your email address will not be published. Required fields are marked *