概念:
uv(unique visitor):独立访客,将每个独立上网电脑(以cookie为依据)视为一位访客,一天之内(00:00-24:00),访问您网站的访客数量。一天之内相同cookie的访问只被计算1次
PV(页面浏览量)是指用户每次访问网站时所产生的点击量或页面浏览量,记录为1次。用户对同一页面的多次访问,访问量值累计
统计独立ip:00:00-24:00内相同ip地址只被计算一次,做网站优化的朋友最关心这个
先声明下环境,此次运行的nginx版本1.7,后端tomcat运行的是动态交互程序(需进行用户认证,如果是静态页面则抓不到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为变量,具体内容在下面定义,也可在日志格式里写入$http_cookie 显示完整的cookie内容<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 ~* "(.*)$") 匹配所有内容 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统计
可统计单个链接地址访问量:
[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统计
[root@localhost logs]# awk '{print $10}' host.access.log | sort -r |uniq -c |wc -l
cookie 测试页面
关于种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); //列出已经存在的 </script> </p> </body> </html>
以上是NGINX怎么统计网站的PV、UV、独立IP的详细内容。更多信息请关注PHP中文网其他相关文章!

NGINX适合高并发和低资源消耗场景,Apache适用于需要复杂配置和功能扩展的场景。 1.NGINX以高性能处理大量并发连接着称。 2.Apache以稳定性和丰富模块支持见长。选择时需根据具体需求决定。

NGINXisessentialformodernwebapplicationsduetoitsrolesasareverseproxy,loadbalancer,andwebserver,offeringhighperformanceandscalability.1)Itactsasareverseproxy,enhancingsecurityandperformancebycachingandloadbalancing.2)NGINXsupportsvariousloadbalancingm

通过Nginx配置SSL/TLS来确保网站安全,需要以下步骤:1.创建基本配置,指定SSL证书和私钥;2.优化配置,启用HTTP/2和OCSPStapling;3.调试常见错误,如证书路径和加密套件问题;4.应用性能优化建议,如使用Let'sEncrypt和会话复用。

Nginx是高性能的HTTP和反向代理服务器,擅长处理高并发连接。1)基本配置:监听端口并提供静态文件服务。2)高级配置:实现反向代理和负载均衡。3)调试技巧:检查错误日志和测试配置文件。4)性能优化:启用Gzip压缩和调整缓存策略。

Nginx缓存可以通过以下步骤显着提升网站性能:1)定义缓存区和设置缓存路径;2)配置缓存有效期;3)根据不同内容设置不同的缓存策略;4)优化缓存存储和负载均衡;5)监控和调试缓存效果。通过这些方法,Nginx缓存能减少后端服务器压力,提升响应速度和用户体验。

使用DockerCompose可以简化Nginx的部署和管理,通过DockerSwarm或Kubernetes进行扩展是常见的做法。1)使用DockerCompose定义和运行Nginx容器,2)通过DockerSwarm或Kubernetes实现集群管理和自动扩展。

Nginx的高级配置可以通过服务器块和反向代理实现:1.服务器块允许在一个实例中运行多个网站,每个块独立配置。2.反向代理将请求转发到后端服务器,实现负载均衡和缓存加速。

Nginx性能调优可以通过调整worker进程数、连接池大小、启用Gzip压缩和HTTP/2协议、使用缓存和负载均衡来实现。1.调整worker进程数和连接池大小:worker_processesauto;events{worker_connections1024;}。2.启用Gzip压缩和HTTP/2协议:http{gzipon;server{listen443sslhttp2;}}。3.使用缓存优化:http{proxy_cache_path/path/to/cachelevels=1:2k


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

记事本++7.3.1
好用且免费的代码编辑器

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器