Analyze Nginx Logs$s _line = ' 1.202.39.44--[22/mar/2016:17:12:25 +0800] "Post/auth/login http/1.1" 261 /login "" mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.87 safari/537.36 ""-"'; $p = '/^ (\d{1,3}.\d{1,3}.\d{1,3}. \d{1,3}) \s-\s (. *) \s\[(. *) \]\s "(. *) \" \s (\d{3}) \s (\d+) \s "(. *)" \s "(. *)" \s\ "(. *) \" $/u ";
Preg_match ($p, $s _line, $a _match); Var_dump ($a _match);
array {[0] = string (233) "1.202.39.44--[22/mar/2016:17:12:25 +0800]" Post/auth/login http/1.1 " 261 "Http://www.halfcookie.cn/auth/login" "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.87 safari/537.36 ""-"" ' IP ' = + string (11) "1.202.39.44 "[1] = = string (one)" 1.202.39.44 "[2] = = string (1)"-"' time ' = = string" 22/mar/2016:17:12:25 +0800 "[ 3] = = string (+) "22/mar/2016:17:12:25 +0800" [4] = = string (+) "Post/auth/login http/1.1" ' status ' = Stri Ng (3) "A" [5] = = string (3) "A" [6] = = string (3) "261" [7] = string (+) "http://www.halfcookie.cn/auth/ Login "[8] = = String (108)" mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.87 safari/537.36 "[9] = = string (1)"-"}
$s _line = ' 1.202.39.44--[22/mar/2016:17:12:25 +0800] "Post/auth/login http/1.1" 261 /login "" mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.87 safari/537.36 ""-"'; $p = '/^ (? P
\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}) \s-\s (. *) \s\[(?) P
. *) \]\s "(. *)" \s (? P
\d{3}) \s (\d+) \s\ "(. *) \" \s\ "(. *)" \s\ "(. *)"/u "
;
Preg_match ($p, $s _line, $a _match); Var_dump ($a _match);
Array { [0] = = string (233) "1.202.39.44--[22/mar/2016:17:12:25 +0800]" Post/auth/login http/1.1 "200 26 1 "Http://www.halfcookie.cn/auth/login" "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.87 safari/537.36 ""-"" ' ip ' = + string (11) " 1.202.39.44 " [1] = = string (one)" 1.202.39.44 " [2] = = string (1)"-" ' time ' = = string (+) "22/mar/2016:17:12:25 +0800" [3] = string (+) "22/mar/2016:17:12:25 +0800" [4] = = String "Post/auth/login http/1.1" ' status ' + string (3) "3" [5] = = string () "200" [6] = = string (3) "261" [7] = = string (+) "Http://www.halfcookie.cn/auth/login" [8] = = String (108) "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.87 safari/537.36 " [9] = = string (1)"-"}
Analytical:
? P
:
named capturing group
Nginx Configuration Log Document:
https://www.ttlsa.com/linux/the-nginx-log-configuration/
The above describes the Nginx log data extraction, including nginx aspects of the content, I hope that the PHP tutorial interested in a friend helpful.