Nginx log Data extraction Nginx apache nginx php nginx rewrite

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.