nginx服务日志

1、error_log 错误日志

    1)错误日志其格式不支持自定义

    2)如何关闭 error_log off 

    3)存放位置及等级 error_log file | stderr [debug | info | notice | warn | error | crit | alert | emerg]

        示例 error_log logs/error.log error

    此指令可在全局块,http块,server块以及location块中配置。


2、access_log 访问日志

    1)使用语法 

access_log path [ format [ buffer = size [ flush = time ]]]

    2)如何关闭

 access_log off

    3)默认值

 access_log logs/access.log combined
 #combined是默认的日志格式

    此指令可在http块,server块以及location块中配置。


3、log_format 日志格式

    1)使用语法

log_format name string ...

    2)默认的log_format

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

    3)日志格式允许的变量

$remote_addr, $http_x_forwarded_for 记录客户端IP地址
$remote_user 记录客户端用户名称
$request 记录请求的URL和HTTP协议
$status 记录请求状态
$body_bytes_sent 发送给客户端的字节数,不包括响应头的大小; 该变量与Apache模块mod_log_config里的“%B”参数兼容。
$bytes_sent 发送给客户端的总字节数。
$connection 连接的序列号。
$connection_requests 当前通过一个连接获得的请求数量。
$msec 日志写入时间。单位为秒,精度是毫秒。
$pipe 如果请求是通过HTTP流水线(pipelined)发送,pipe值为“p”,否则为“.”。
$http_referer 记录从哪个页面链接访问过来的
$http_user_agent 记录客户端浏览器相关信息
$request_length 请求的长度(包括请求行,请求头和请求正文)。
$request_time 请求处理时间,单位为秒,精度毫秒; 从读入客户端的第一个字节开始,直到把最后一个字符发送给客户端后进行日志写入为止。
$time_iso8601 ISO8601标准格式下的本地时间。
$time_local 通用日志格式下的本地时间。

    4)示例,就看combined的输出好了。

172.17.22.198 - - [07/Apr/2016:12:04:02 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36 QQBrowser/3.9.3952.400"

 

   此指令只能在http块中配置

转载于:https://my.oschina.net/sluggarddd/blog/654948

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值