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 MySQL, multi-table join query is a ver...
Table of contents background 1) Enable the keepch...
This article example shares the specific code of ...
Table of contents 1. Sample code 2. See the essen...
Using CI to build docker images for release has g...
Some time ago, when I was working on a small func...
Table of contents Tutorial Series 1. Backup strat...
Effect picture (if you want a triangle, please cl...
This article shares with you how to query the sta...
Table of contents Overview Defining methods on an...
Recently, a friend asked me a question: When layo...
Table of contents Preface 1. Set the prototype on...
Add the following code to the CSS style of the el...
background A specific device is used to perform i...
The "nofollow" tag was proposed by Goog...