Nginx: PV, UV, independent IP Everyone who makes websites knows that they often need to check the website's PV, UV and other website access data. Of course, if the website has a CDN, the nginx local log is meaningless. The following is a statistical analysis of the log access data of the nginx website; concept:
First, let's state the environment. This time, we are running nginx version 1.7, and the backend Tomcat is running a dynamic interactive program (user authentication is required. If it is a static page, the cache value cannot be captured, and $http_cookie is empty). That's it; nginx log file configuration http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - [$time_local] "$request" ' ' - $status "User_Cookie:$guid" '; #User_Cookie is the log display character, $guid is a variable, the specific content is defined below, you can also write $http_cookie in the log format to display the complete cookie content<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 ~* "(.*)$") matches all contentif ( $http_cookie ~* "CSID=([A-Z0-9]*)"){ set $guid $1; } #Only match CSID character information, here is a regular expression<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; } } Note: The values in $http_cookie are cookie values, separated by ";" Log output format
PV Statistics The number of visits to a single link address can be counted: [root@localhost logs]# grep index.shtml host.access.log | wc -l Total PV: [root@localhost logs]# awk '{print $6}' host.access.log | wc -l Dedicated IP [root@localhost logs]# awk '{print $1}' host.access.log | sort -r | uniq -c | wc -l UV Statistics [root@localhost logs]# awk '{print $10}' host.access.log | sort -r | uniq -c | wc -l Cookie Test Page Regarding the type of cookies, you can use the following HTML code to edit and add the cookies you need to type: #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"> //For testing purposes, refresh the page every 10 seconds</head> <body> <h1>test.test.com domain test</h1> The cookies for this domain are listed below<br> <p> <script> document.cookie="guid=A1UD8E5512451111111111"; //Kind cookies, appenddocument.cookie="city=beijing"; //Kind cookies, appenddocument.write(document.cookie); //List existing</script> </p> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Introduction to MySQL isolation level, lock and MVCC
>>: 7 native JS error types you should know
Preface In today's increasingly convenient In...
This article shares with you the installation tut...
There are the following log files in MySQL: 1: re...
Latest solution: -v /usr/share/zoneinfo/Asia/Shan...
background Since I was assigned to a new project ...
MySQL paging analysis principle and efficiency im...
1. Multiple borders[1] Background: box-shadow, ou...
This article introduces 4 methods to achieve mask...
Preface: position:sticky is a new attribute of CS...
I have never used apache. After I started working...
One port changes In version 3.2.0, the namenode p...
Table of contents Docker version Install Docker E...
6 solutions for network failure in Docker contain...
<br /> English original: http://desktoppub.a...
Before talking about CSS priority, we need to und...