发表于: 2018-03-13 08:01:47

3 1027


【今天完成的事】


1.分析Nginx日志的每行内容


127.0.0.1 - - [12/Mar/2018:09:37:21 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36" "-"
127.0.0.1 - - [12/Mar/2018:10:25:14 +0800] "GET / HTTP/1.1" 200 1556 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299" "-"
127.0.0.1 - - [12/Mar/2018:10:25:14 +0800] "GET /index.css HTTP/1.1" 200 0 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299" "-"
127.0.0.1 - - [12/Mar/2018:10:25:14 +0800] "GET /index.css HTTP/1.1" 200 562 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299" "-"
127.0.0.1 - - [12/Mar/2018:20:13:36 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36" "-"


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


客户端地址                                $remote_addr             127.0.0.1
客户端用户名称                         $remote_user              -
访问时间和时区                         $time_local                  12/Mar/2018:09:37:21 +0800
请求的URI和HTTP协议             $request                       GET /favicon.ico HTTP/1.1
HTTP请求状态                           $status                         404
发送给客户端文件内容大小        $body_bytes_sent        571
url跳转来源                                 $http_referer                http://localhost/
用户终端浏览器等信息               $http_user_agent         Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
HTTP的请求端真实的IP             $http_x_forwarded_for        -


看了前面师兄的日报 他理解的任务1是要统计每个客户端地址的出现次数 由大到小列出前十名
但是我的nginx日志每行中的客户端地址都是127.0.0.1 这样统计出来的结果毫无意义
然后尝试了很多办法 开了个虚拟机 用虚拟机的浏览器访问本机的网站 日志如下


192.168.0.105 - - [12/Mar/2018:20:59:57 +0800] "GET / HTTP/1.1" 200 1556 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"
192.168.0.105 - - [12/Mar/2018:20:59:58 +0800] "GET /index.css HTTP/1.1" 200 562 "http://192.168.0.105/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"
192.168.0.105 - - [12/Mar/2018:21:01:29 +0800] "GET http://www.baidu.com/ HTTP/1.0" 200 1556 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"
192.168.0.105 - - [12/Mar/2018:21:01:29 +0800] "GET http://www.baidu.com/index.css HTTP/1.0" 200 562 "http://www.baidu.com" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"
192.168.0.105 - - [12/Mar/2018:21:01:45 +0800] "GET http://www.baidu.com/ HTTP/1.0" 304 0 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"


这次客户端地址变成了192.168.0.105 这个地址是本机的IP 好像也不是我想要的结果
又试过了用ngrok内网穿透 从外网访问 结果还是127.0.0.1 很无奈 为什么别人的日志是这样的


192.168.68.62 - - [23/Jan/2018:13:36:41 +0800] "GET /general/ipanel/user/user_count.php?CHECK_SMS=1&CLIENT=2&_=1514353004443 HTTP/1.1" 200 237 "http://192.168.1.18/ispirit/index.php?I_VER=2" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.138 Safari/537.36" "-"
192.168.50.5 - - [23/Jan/2018:13:36:41 +0800] "GET /ispirit/im/count.php?TYPE=email,sms,taskcenter,sns HTTP/1.1" 200 17 "-" "ispiritPro" "-"
192.168.10.211 - - [23/Jan/2018:13:36:44 +0800] "GET /general/ipanel/user/user_count.php?CHECK_SMS=1&CLIENT=2&_=1514353132409 HTTP/1.1" 200 237 "http://192.168.1.18/ispirit/index.php?I_VER=2" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.138 Safari/537.36" "-"
192.168.90.226 - - [23/Jan/2018:13:36:45 +0800] "GET /ispirit/im/count.php?TYPE=email,sms,taskcenter,sns HTTP/1.1" 200 18 "-" "ispiritPro" "-"


每个IP都不一样 他是不是有服务器?有正在运营的网站? 那我没有怎么办
后来看了看nginx正向代理、反向代理相关的内容 可能问题还是出在nginx的配置上


【遇到的问题】
nginx日志每个客户端地址都是127.0.0.1 这样统计的结果没有意义


【明天的计划】
尝试配置nginx的代理


【收获】
了解了nginx日志的格式内容



返回列表 返回列表
评论

    分享到