NGINX怎么統(tǒng)計網(wǎng)站的PV、UV、獨立IP

本篇內(nèi)容介紹了“NGINX怎么統(tǒng)計網(wǎng)站的PV、UV、獨立IP”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

專注于為中小企業(yè)提供網(wǎng)站設(shè)計制作、成都做網(wǎng)站服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)樂安免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了近1000家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

概念:

  • uv(unique visitor):獨立訪客,將每個獨立上網(wǎng)電腦(以cookie為依據(jù))視為一位訪客,一天之內(nèi)(00:00-24:00),訪問您網(wǎng)站的訪客數(shù)量。一天之內(nèi)相同cookie的訪問只被計算1次

  • pv(page view):訪問量,即頁面瀏覽量或者點擊量,用戶每次對網(wǎng)站的訪問均被記錄1次。用戶對同一頁面的多次訪問,訪問量值累計

  • 統(tǒng)計獨立ip:00:00-24:00內(nèi)相同ip地址只被計算一次,做網(wǎng)站優(yōu)化的朋友最關(guān)心這個

先聲明下環(huán)境,此次運行的nginx版本1.7,后端tomcat運行的是動態(tài)交互程序(需進行用戶認(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)容<br>
  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字符信息,此處為正則表達式<br>
    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這個里面的值是一個一個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)計

可統(tǒng)計單個鏈接地址訪問量:

[root@localhost logs]# grep index.shtml host.access.log | wc -l

總pv量:

[root@localhost logs]# awk '{print $6}' host.access.log | wc -l

獨立ip

[root@localhost logs]# awk '{print $1}' host.access.log | sort -r |uniq -c | wc -l

uv統(tǒng)計

[root@localhost logs]# awk '{print $10}' host.access.log | sort -r |uniq -c |wc -l

cookie 測試頁面

關(guān)于種cookie,可以使用下面的html代碼,編輯,添加需要種的cookie

#index.html
 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gbk">
<meta http-equiv="refresh" content="10"> //為了方便測試,每10秒刷新一次頁面
</head>
<body>
<h1>test.test.com域測試</h1>
下面列出了該域的cookie<br>
<p>
<script>
document.cookie="guid=a1ud8e5512451111111111"; //種cookie,追加
document.cookie="city=beijing"; //種cookie,追加
document.write(document.cookie); //列出已經(jīng)存在的
</script>
</p>
</body>
</html>

“NGINX怎么統(tǒng)計網(wǎng)站的PV、UV、獨立IP”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

名稱欄目:NGINX怎么統(tǒng)計網(wǎng)站的PV、UV、獨立IP
文章起源:http://www.muchs.cn/article34/ghjhpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)定制網(wǎng)站、營銷型網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站、網(wǎng)頁設(shè)計公司ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管