My website now uses Nginx + php. Now I want to count the number of visiting users and observe the footprints of a person on the website. I don't want to use php, because every access should be recorded once. php is inefficient and I want to print it directly in nginxaccesslog. The solution I came up with is: log... now my website uses Nginx + php. Now I want to count the visiting login users and observe the footprints of a person on the website. I don't want to use php, because every access should be recorded once. php is inefficient and I want to print it directly in nginx access log.
The solution I came up with was to record the user from which each access entry came from in the log (if the user is logged on, the user ID is recorded, and a key value can be given to the user without logon, used to indicate his identity), and then combined with other content recorded in the nginx access log, you can compare the good-looking statistics report.
The problem is, I don't know how to do this record... The user's URL cannot contain his or her ID...
Reply content:
My website now uses Nginx + php. Now I want to count the number of visiting users and observe the footprints of a person on the website. I don't want to use php, because every access should be recorded once. php is inefficient and I want to print it directly in nginx access log.
The solution I came up with was to record the user from which each access entry came from in the log (if the user is logged on, the user ID is recorded, and a key value can be given to the user without logon, used to indicate his identity), and then combined with other content recorded in the nginx access log, you can compare the good-looking statistics report.
The problem is, I don't know how to do this record... The user's URL cannot contain his or her ID...
This is simple .. Make an ajax request on the page, and the URL will carry the UID. nginx will write it down, and the corresponding log will be easily extracted.
For more flexible processing of log formats, we recommend that you directly use the ngx_lua module. In this way, you can customize the log format, and the records can be directly imported into the database for processing, which is very convenient.
I don't have a clear idea, but I think nginx can be something at the http protocol level. All http-related data can be recorded, but it involves something at the ID business level, i'm afraid it is not easy to do. If you want to do this, you also need to check whether the program can work with nginx variable parameters.
In addition, the business program must output many other logs, which is inevitable.