码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 访问日志配置

时间:2017-05-25 19:47:19      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:worker   windows   状态码   net   nec   访问   配置   proc   字节   

[root@localhost conf]# cat nginx.conf
worker_processes  1;
error_log  logs/error.log  error;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include     vhosts/*.conf;
    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘   # 先定义日志格式,main是日志格式的名字
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;
    access_log  logs/access.log  main;                                          # 使用日志格式,也可以把这一行放到想记录访问日志的虚拟主机配置文件中去
}
$remote_addr :记录访问网站的客户端地址
$remote_user :记录远程客户端用户名称
$time_local :记录访问时间与时区
$request :记录用户的 http 请求起始行信息
$status :记录 http 状态码,即请求返回的状态,例如 200404502 等
$body_bytes_sent :记录服务器发送给客户端的响应 body 字节数
$http_referer :记录此次请求是从哪个链接访问过来的,可以根据 referer 进行防盗链设置
$http_user_agent :记录客户端访问信息,如浏览器、手机客户端等
$http_x_forwarded_for :当前端有代理服务器时,设置 Web 节点记录客户端地址的配置,此参数生效的前提是代理服务器上也进行了相关的 x_forwarded_for 设置

 

产生的日志:

192.168.5.1 - - [25/May/2017:18:27:51 +0800] "GET / HTTP/1.1" 200 12 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)" "-"
$remote_addr 对应的是 192.168.5.1 ,即客户端的 IP 地址
$remote_user 对应的是 - ,没有远程用户,所以用 - 填充
$time_local 对应的是 [25/May/2017:18:27:51 +0800]
$request 对应的是 "GET / HTTP/1.1"
$status 对应的是状态码 200 ,表示访问正常
$body_bytes_sent 对应的是 12 字节,即响应 body 的大小
$http_referer 对应的是 "-" ,由于是直接打开域名浏览的,因此 referer 没有值
$http_user_agent 对应的是 "Mozilla/4.0 (compatible; MSIE........)"
$http_x_forwarded_for 对应的是 "-" ,因为 Web 服务没有使用代理,所以用 "-" 填充

 

 

 

 

    

 

 

    

Nginx 访问日志配置

标签:worker   windows   状态码   net   nec   访问   配置   proc   字节   

原文地址:http://www.cnblogs.com/pzk7788/p/6905398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!