How to use nginx to count url with specific parameters

problem description

there is a demand now. A website can be accessed directly with url. Or access it with an email link with an identified parameter. Now you need to record the number of times you visit the site through an e-mail link. Asked to do it in nginx.

the environmental background of the problems and what methods you have tried

has not used nginx. There is nothing I can do

related codes

/ / Please paste the code text below (do not replace the code with pictures)
none

Apr.25,2021

you can analyze the access.log of nginx


upstairs + 1. Nginx's default access log format already includes the query params parameter, so you can quickly count


even if you use grep | wc .

you can first write a Linux script to count the access log of nginx, and then call this script in Java
shell script content can be simple grep or awk

java call script code is as follows:

Process process = Runtime.getRuntime().exec("shell.sh");
int execSuccess = process.waitFor();
if (0 == execSuccess) {
    bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String resultAmount = "";
    while ((resultAmount = bufferedReader.readLine()) != null) {
        result.append(resultAmount);
    }
    return result.toString().trim();
}
The logical expression ability of

nginx itself is limited, so you can use lua, for analysis and statistics through Lua.

Menu