Nginx打点服务器配置
什么是打点服务器 他的作用是什么
打点服务器就是记录用户行为的服务器
单独从应用独立出来 目的就是为了减轻应用服务器压力
效果如下:
10.0.1.1 - - [05/Feb/2020:16:39:11 -0500] "GET /dig?time=2020%2F2%2F6%20%E4%B8%8B%E5%8D%882%3A08%3A11&url=file%3A%2F%2F%2FC%3A%2FUsers%2FAdministrator%2FDesktop%2F%25E6%2589%2593%25E7%2582%25B9%25E6%25B5%258B%25E8%25AF%2595%2Findex.html&refer= HTTP/1.1" 200 43 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3710.0 Safari/537.36" "-"
1 前端上报dadian.js
$(()=>{ $.get("http://10.0.1.101:8008/dig",{ //http://10.0.1.101:8008/dig 打点服务器地址 "time" : gettime(), "url" : geturl(), "refer": getrefer(), // "us" : getuser_agent(), //"cookie": getcookie() // ip 和 user_agent可以通过nginx直接获得 }) }) // gettime(); //js获取当前时间 // geturl(); //js获取客户端当前url // getrefer(); //js获取客户端当前页面的上级页面的url // getuser_agent(); //js获取客户端类型 // getcookie() //js获取客户端cookie function gettime(){ var nowDate = new Date(); return nowDate.toLocaleString(); } function geturl(){ return window.location.href; } function getrefer(){ return document.referrer; } function getcookie(){ return document.cookie; } function getuser_agent(){ return navigator.userAgent; }
nginx配置 nginx.conf
最好使用编译安装的nginx 很多集成环境没有带需要ngx_http_empty_gif_module
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; 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; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8008; server_name localhost; #charset koi8-r; access_log logs/dig.log main; location = /dig { empty_gif; error_page 405 =200 $request_uri; } } }
来源:https://www.cnblogs.com/ham-731/p/12268548.html