本篇內(nèi)容介紹了“NGINX怎么統(tǒng)計(jì)網(wǎng)站的PV、UV、獨(dú)立IP”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)樂安免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
概念:
uv(unique visitor):獨(dú)立訪客,將每個(gè)獨(dú)立上網(wǎng)電腦(以cookie為依據(jù))視為一位訪客,一天之內(nèi)(00:00-24:00),訪問您網(wǎng)站的訪客數(shù)量。一天之內(nèi)相同cookie的訪問只被計(jì)算1次
pv(page view):訪問量,即頁面瀏覽量或者點(diǎn)擊量,用戶每次對(duì)網(wǎng)站的訪問均被記錄1次。用戶對(duì)同一頁面的多次訪問,訪問量值累計(jì)
統(tǒng)計(jì)獨(dú)立ip:00:00-24:00內(nèi)相同ip地址只被計(jì)算一次,做網(wǎng)站優(yōu)化的朋友最關(guān)心這個(gè)
先聲明下環(huán)境,此次運(yùn)行的nginx版本1.7,后端tomcat運(yùn)行的是動(dòng)態(tài)交互程序(需進(jìn)行用戶認(rèn)證,如果是靜態(tài)頁面則抓不到cache值,$http_cookie是空值),就是這樣;
nginx日志文件配置
http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - [$time_local] "$request" ' ' - $status "user_cookie:$guid" '; #user_cookie為日志顯示字符,$guid為變量,具體內(nèi)容在下面定義,也可在日志格式里寫入$http_cookie 顯示完整的cookie內(nèi)容
sendfile on; keepalive_timeout 65; upstream backserver { ip_hash; server 1.1.2.2:8080; server 1.1.2.3:8080; } server { listen 80; server_name localhost; #if ( $http_cookie ~* "(.*)$") 匹配所有內(nèi)容 if ( $http_cookie ~* "csid=([a-z0-9]*)"){ set $guid $1; } #只匹配csid字符信息,此處為正則表達(dá)式
access_log logs/host.access.log main; location ~* ^(.*)$ { #limit_req zone=allips burst=1 nodelay; proxy_pass http://backserver; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header remote-host $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; client_max_body_size 8m; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
注:$http_cookie這個(gè)里面的值是一個(gè)一個(gè)cookie的值,中間以“;”分隔
日志輸出格式
192.168.40.2 - [02/nov/2016:15:44:35 +0800] "get /wcm/app/main/refresh.jsp?r=1478072325778 http/1.1" - 200 "user_cookie:7f00000122a5597c46607b1c0a7ec016"
192.168.40.2 - [02/nov/2016:15:44:35 +0800] "get /webpic/w0201611/w020161102/w020161102566715167404.jpg http/1.1" - 200 "user_cookie:7f00000122a5597c46607b1c0a7ec016"
119.255.31.109 - [02/nov/2016:15:44:36 +0800] "get /wcm/app/main/refresh.jsp?r=1478072510132 http/1.1" - 200 "user_cookie:7f000001237921be9237838aec65704d"
119.255.31.109 - [02/nov/2016:15:44:36 +0800] "get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1" - 200 "user_cookie:7f000001237921be9237838aec65704d"
192.168.40.2 - [02/nov/2016:15:44:37 +0800] "get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1" - 200 "user_cookie:7f00000123d3bf2345115eaac21f71e0"
192.168.40.2 - [02/nov/2016:15:44:37 +0800] "get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1" - 200 "user_cookie:7f00000123ef73896df98eda9950944e"
192.168.40.2 - [02/nov/2016:15:44:37 +0800] "get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1" - 200 "user_cookie:7f00000123fe0f9c397e1a8f0c4f044b"
192.168.40.2 - [02/nov/2016:15:44:37 +0800] "get /wcm/app/main/refresh.jsp?r=1478072511427 http/1.1" - 200 "user_cookie:7f00000123a465b7ea1de0af0ae671b7"
119.255.31.109 - [02/nov/2016:15:44:38 +0800] "get /wcm/app/message/message_query_service.jsp?readflag=0&msgtypes=1%2c2%2c3 http/1.1" - 200 "user_cookie:7f00000123d89b11302df80ae773c900"
pv統(tǒng)計(jì)
可統(tǒng)計(jì)單個(gè)鏈接地址訪問量:
[root@localhost logs]# grep index.shtml host.access.log | wc -l
總pv量:
[root@localhost logs]# awk '{print $6}' host.access.log | wc -l
獨(dú)立ip
[root@localhost logs]# awk '{print $1}' host.access.log | sort -r |uniq -c | wc -l
uv統(tǒng)計(jì)
[root@localhost logs]# awk '{print $10}' host.access.log | sort -r |uniq -c |wc -l
cookie 測(cè)試頁面
關(guān)于種cookie,可以使用下面的html代碼,編輯,添加需要種的cookie
#index.html //為了方便測(cè)試,每10秒刷新一次頁面test.test.com域測(cè)試
下面列出了該域的cookie
“NGINX怎么統(tǒng)計(jì)網(wǎng)站的PV、UV、獨(dú)立IP”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!