标签:
log_format是指存储日志的时候所采用的格式,可以在/usr/local/nginx/conf/nginx.conf的http字段中设置
下面是一个典型的log_format设置
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘;
其中
1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
2.$remote_user :用来记录客户端用户名称;
3.$time_local : 用来记录访问时间与时区;
4.$request : 用来记录请求的url与http协议;
5.$status : 用来记录请求状态;成功是200,
6.$body_bytes_s ent :记录发送给客户端文件主体内容大小;
7.$http_referer :用来记录从那个页面链接访问过来的;
8.$http_user_agent :记录客户端浏览器的相关信息
在http字段中设置了之后还需要在server字段中采用如下
server { listen 80; access_log logs/host.access.log main; //省略部分代码 }
这样就可以在写入日志的时候采用main的格式了
下面是一些从access.log里面提取的访问日志
220.181.108.169 - - [03/Apr/2015:19:07:52 +0800] "GET /feed HTTP/1.1" 499 0 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" "-" 27.159.224.22 - - [03/Apr/2015:19:10:51 +0800] "GET /p/5180.html HTTP/1.1" 499 0 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727 ; .NET CLR 4.0.30319)" "-" 207.46.13.112 - - [03/Apr/2015:19:11:28 +0800] "GET /p/11436.html/feed HTTP/1.1" 499 0 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" "-" 123.118.249.160 - - [03/Apr/2015:19:11:48 +0800] "GET /register.php#breadCrumb HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1" "-" 123.118.249.160 - - [03/Apr/2015:19:11:48 +0800] "GET /register.php HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1" "-"
标签:
原文地址:http://www.cnblogs.com/yiluxiuxing/p/4390895.html