微信搜索superit|邀请体验:大数据, 数据管理、OLAP分析与可视化平台 | 赞助作者:赞助作者

nginx的埋点服务器配置empty_gif

架构 aide_941 4℃ 0评论

empty_gif是内存1×1的图片,nginx自带的模块,直接下载windows或者linux下的nginx就可以,下载地址:

windows/linux:  https://nginx.org/en/download.html

 

windows配置例子


worker_processes  4;
error_log logs/error.log warn;
pid       nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format main '$time_iso8601 | TSS | $remote_addr | $http_host | $status | $request_time | $request_length | $body_bytes_sent | $http_user_agent | $request_uri | $request_body';
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen 8888;
        server_name localhost 127.0.0.1 10.161.22.84 10.161.83.23 10.161.203.1;
        if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})") {
            set $year $1;
            set $month $2;
            set $day $3;
            set $hour $4;
            set $minute $5;
        }
        access_log logs/TSS-$year$month$day.log main;
        index index.htm index.html;
        root html;
        location = /favicon.ico {
            log_not_found off;
            access_log off; 
        }
        location = /dig.gif {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';

            # if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204;
            # }
            empty_gif;
        }
    }
}

 

 

 

$(document).ajaxSend(function (event, jqXHR, settings) {
    if (!settings.url.includes('/dig.gif')
        && !settings.url.includes('/GetWaitLineInfo')
        && !settings.url.includes('/GetMarquee')    ) {
        const log = {
            type: 'ajax-send',
            url: settings.url,
            method: settings.type,
            data: settings.data,
            timestamp: Date.now()
        };
        if (!navigator.sendBeacon) {
            return;
        }
        navigator.sendBeacon("http://127.0.0.1:8888/dig.gif?t=send&url=" + settings.url + "&" + (settings.data), JSON.stringify(log));
    }
});

$(document).ajaxComplete(function (event, xhr, settings) {
    if (!settings.url.includes('/dig.gif')
        && !settings.url.includes('/GetWaitLineInfo')
        && !settings.url.includes('/GetMarquee')    ) {
        const log = {
            type: 'ajax-complete',
            url: settings.url,
            status: xhr.status,
            response: xhr.responseText,
            timestamp: Date.now()
        };
        if (!navigator.sendBeacon) {
            return;
        }
        fetch("http://127.0.0.1:8888/dig.gif?t=back&url=" + settings.url + "&" + (settings.data) + "&s=" + xhr.status + "&resp=" + (xhr.responseText.length > 100 ? xhr.responseText.substring(100) : xhr.responseText), {
            method: 'POST',
            body: JSON.stringify(log),
            headers: {
                'Content-Type': 'application/json'
            }
        });
    }
});

 

 

在这里插入图片描述
在这里插入图片描述

切换到 Nginx 安装目录下,双击 Nginx.exe 启动 Nginx

在这里插入图片描述
在这里插入图片描述

 

 

 

 

转载请注明:SuperIT » nginx的埋点服务器配置empty_gif

喜欢 (0)or分享 (0)

您必须 登录 才能发表评论!