nginx日志数据提取 nginx apache nginx php nginx rewrite
程序员文章站
2022-05-22 19:54:09
...
分析nginx日志$s_line = '1.202.39.44 - - [22/Mar/2016:17:12:25 +0800] "POST /auth/login HTTP/1.1" 200 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" "-"'; $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(13) { [0] => string(233) "1.202.39.44 - - [22/Mar/2016:17:12:25 +0800] "POST /auth/login HTTP/1.1" 200 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(11) "1.202.39.44" [2] => string(1) "-" 'time' => string(26) "22/Mar/2016:17:12:25 +0800" [3] => string(26) "22/Mar/2016:17:12:25 +0800" [4] => string(25) "POST /auth/login HTTP/1.1" 'status' => string(3) "200" [5] => string(3) "200" [6] => string(3) "261" [7] => string(35) "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" 200 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" "-"'; $p = '/^(?P\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s-\s(.*)\s\[(?P preg_match($p,$s_line,$a_match); var_dump($a_match);array(13) { [0] => string(233) "1.202.39.44 - - [22/Mar/2016:17:12:25 +0800] "POST /auth/login HTTP/1.1" 200 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(11) "1.202.39.44" [2] => string(1) "-" 'time' => string(26) "22/Mar/2016:17:12:25 +0800" [3] => string(26) "22/Mar/2016:17:12:25 +0800" [4] => string(25) "POST /auth/login HTTP/1.1" 'status' => string(3) "200" [5] => string(3) "200" [6] => string(3) "261" [7] => string(35) "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) "-" }解析:
?P
:命名捕获组 nginx配置日志文档。。
https://www.ttlsa.com/linux/the-nginx-log-configuration/
以上就介绍了nginx日志数据提取,包括了nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: 正确编译ijkplayer
下一篇: 海思3559平台移植二维码解码库zbar
推荐阅读
-
PHP统计nginx访问日志中的搜索引擎抓取404链接页面路径
-
PHP、Nginx、Apache中禁止网页被iframe引用的方法
-
nginx比apache处理静态文件速度快,但是nginx处理大量并发的php请求时,容易出现502错误,频率大概是多少
-
PHP连接Nginx服务器并解析Nginx日志的方法
-
nginx php-fpm中启用慢日志配置(用于检测执行较慢的PHP脚本)
-
Nginx、Apache、Lighttpd禁止目录执行php配置示例
-
APMServ一键快速搭建Apache+PHP+MySQL+Nginx+Memcached+ASP运行平台教程
-
实现Nginx中使用PHP-FPM时记录PHP错误日志的配置方法
-
python实现分析apache和nginx日志文件并输出访客ip列表的方法
-
Linux下查看nginx apache mysql php的编译参数