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 terms of layout, Gobang is much simple...
I was playing with CentOS in a VMware virtual mac...
Basics 1. Use scaffolding to create a project and...
Win10 installs mysql5.7 decompressed version, for...
This article describes the support and problem so...
Description Solution VMware 15 virtual machine br...
A few days ago, I watched a video of a foreign gu...
Before, I had built WordPress myself, but at that...
<!DOCTYPE html> <html lang="en"...
This article mainly introduces the differences be...
pt-heartbeat When the database is replicated betw...
There are 4 commonly used methods, as follows: 1....
Log in to MySQL first shell> mysql --user=root...
HTML5 and jQuery implement the preview of local i...
In the past, float was often used for layout, but...