1. 程式人生 > >nginx 大資料埋點日誌格式

nginx 大資料埋點日誌格式

user  root root;

worker_processes 8;
#指定檔案描述符數量
worker_rlimit_nofile 65535;

#指定錯誤日誌存放的路徑
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

# 指定程序檔案存放的路徑
pid /usr/local/nginx/nginx.pid;

events {
    #使用的網路I/O模型
    use epoll;
    #允許的連線數
    worker_connections 65535;
}

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/local/nginx/modules/*.conf;

http {
    include       mime.types;
    default_type  application/octet-stream;
    charset       utf8;

    log_format access '[$time_iso8601] [$remote_addr] [$remote_user] '
                    '[$scheme] [$request_method] [$request_uri] [$content_type] [$status] '
                    '[$body_bytes_sent] [$http_referer] [$http_user_agent] [$http_x_forwarded_for] '
                    '[$upstream_addr] [$upstream_status] [$upstream_response_time] [$request_time]';

    access_log /usr/local/nginx/logs/access.log  access;
    error_log /usr/local/nginx/logs/error.log;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    server_names_hash_bucket_size 128;
    large_client_header_buffers 4 32k;
    # 允許客戶端請求的最大單個檔案位元組數
    client_max_body_size 8m;
    # 緩衝區代理緩衝使用者端請求的最大位元組數,可以理解為先儲存到本地再傳給使用者
    client_header_buffer_size 32k;
    # 緩衝區代理緩衝使用者端請求的最大位元組數,可以理解為先儲存到本地再傳給使用者
    client_body_buffer_size 128k;
    # 跟後端伺服器連線的超時時間,發起握手等候響應超時時間
    proxy_connect_timeout 600;
    # 連線成功後,等候後端伺服器響應時間,其實已經進入後端的排隊之中等候處理
    proxy_read_timeout 600;
    # 後端伺服器資料回傳時間,就是在規定時間內後端伺服器必須傳完所有的資料
    proxy_send_timeout 600;
    # 代理請求快取區,這個緩衝區間會儲存使用者的頭資訊以供Nginx進行規則處理,一般只能儲存下頭部資訊即可
    proxy_buffer_size 16k;
    # 用上,告訴Nginx儲存單個用的幾個Buffer最大用多大空間
    proxy_buffers 4 32k;
    # 如果系統很忙的時候可以申請更大的proxy_buffers(官方推薦*2)
    proxy_busy_buffers_size 64k;
    # proxy快取臨時檔案的大小
    proxy_temp_file_write_size 64k;

    # fastcgi配置
    fastcgi_connect_timeout 75;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    # 開啟gzip壓縮
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    client_body_temp_path /usr/local/nginx/temp/body_temp/ 1 2 ;
    proxy_temp_path /usr/local/nginx/temp/proxy_temp 1 2;
    fastcgi_temp_path /usr/local/nginx/temp/fastcgi_temp 1 2;
    scgi_temp_path /usr/local/nginx/temp/scgi_temp 1 2;
    uwsgi_temp_path /usr/local/nginx/temp/uwsgi_temp 1 2;

 # upstream front_end {
 #   server 172.20.0.75:8767 weight=1 max_fails=2 fail_timeout=5s;
 #   server 172.20.0.76:8767 weight=1 max_fails=2 fail_timeout=5s;
 # }

    include vhosts/*.conf;

}

server {
    listen       80;
    server_name  localhost;

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Headers' 'Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    location / {
        root   /home/work/zhidaoauto-fe;
        index  /activity/activity.html;
    }
    location /activity/api/v1/games {
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $remote_addr;
       proxy_pass http://activityserver;
    }
    location /activity/api/v1/coin/addGameCoin{
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $remote_addr;
       proxy_pass http://activityserver;
    }

    location ^~ /appMall/ {
        root /home/work/zhidaoauto-fe-app;
        index index.html;
        try_files $uri $uri/ /index.html =404;
    }

    location ~* ^/appMall/.*\.(js|css|gif|jpg|jpeg|png)$ {
        root /home/work/zhidaoauto-fe-app/appMall;
        access_log off;
        expires 1d;
    }

    location ^~ /activity/api/ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://mis;
    }

    location ^~ /mall/api/ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://mallserver;
    }

    location ^~ /mallHttp/api/ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://mallserver;
    }


    location ^~ /coinHttp/api {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://coinserver;
    }

    location ^~ /score/api {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://coinserver;
    }

    location ^~ /images/ {
        root /home/work/zhidaoauto-pic/;
        access_log off;
    }

    location ~* \.(html|htm)$ {
        root /home/work/zhidaoauto-fe;
        add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
    }

    location ~* \.(js|css)$ {
        root /home/work/zhidaoauto-fe;
        access_log off;
        expires 1d;
    }

    location ~* \.(gif|jpg|jpeg|png)$ {
        root /home/work/zhidaoauto-fe;
        access_log off;
        expires 10m;
    }

}

upstream activityserver{
    server 10.2.100.59:8081;
}

upstream mis {
    server 10.2.100.59:8080;
}

upstream coinserver {
    server 10.2.100.59:8861;
    server 10.2.100.49:8861;
}

upstream mallserver {
   server 10.2.100.59:8862;
}