nginx 常用的配置文件有两种: access.log 和 error.log

access.log 的作用是 记录用户所有的访问请求,不论状态码,包括200 ,404,500等请求,404,500的请求并不会出现在error.log中。

error.log 的作用是 记录nginx 本身运行时的一些错误,不会记录用户访问的请求。比如记录模块错误信息日志,以及nginx配置文件的错误日志等,格式不支持自定义,可以设置级别。

access.log 的格式设置:
log_format combined '$remote_addr - $remote_user [$time_local] '
' "$request" $status $body_bytes_sent '
' "$http_referer" "$http_user_agent" '; #日志格式允许包含的变量注释如下:
$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 通用日志格式下的本地时间。 #参考实例
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$gzip_ratio" $request_time $bytes_sent $request_length'; log_format srcache_log '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent $request_time $bytes_sent $request_length '
'[$upstream_response_time] [$srcache_fetch_status] [$srcache_store_status] [$srcache_expire]'; open_log_file_cache max=1000 inactive=60s; server {
server_name ~^(www\.)?(.+)$;
access_log logs/$2-access.log main;
error_log logs/$2-error.log; location /srcache {
access_log logs/access-srcache.log srcache_log;
}
}
}
error.log 配置示例:

#错误日志保存位置
            #error_log logs/error.log;

#指定错误日志的位置和级别

#error_log logs/error.log notice;
           #error_log logs/error.log info;


最新文章

  1. [LeetCode] Longest Common Prefix 最长共同前缀
  2. 三、jQuery--jQuery基础--jQuery基础课程--第4章 jQuery表单选择器
  3. CoreAnimation-03-隐式动画
  4. HD2046骨牌铺方格
  5. unicode 编码在线转换--javascript
  6. Focus相关点滴
  7. Teradata中fastload使用
  8. WIND2003 安装Zend studio 报错
  9. TestNG使用总结
  10. Unity带有网络功能——创建服务,并连接到一个特定的服务
  11. poj2236无线网络
  12. 当浏览器窗体改变时,div跟着变动方法
  13. 页面发送请求到后台报错“Empty or invalid anti forgery header token.”问题解决
  14. Java虚拟机一 运行时数据区(栈、堆、方法区等)
  15. 【Hadoop】3、Hadoop-MapReduce使用avro进行数据的序列化与反序列化
  16. 【转】修改mysql数据库的用户名和密码
  17. composer----------composer初体验,如何安装,如何下载
  18. ArrayList list = new ArrayList()在这个泛型为Integer的ArrayList中存放一个String类型的对象
  19. 第 6 章 存储 - 040 - docker managed volume
  20. Java基础-虚拟内存之映射字节缓冲区(MappedByteBuffer)

热门文章

  1. UAP开发错误之The given System.Uri cannot be converted into a Windows.Foundation.Uri(windows phone背景更换)
  2. CPU多核控速
  3. CentOS7中firewalld的安装与使用详解
  4. Controls 属性与继承 TShape 类的小练习(使用TShape可以解决很多图形问题)
  5. NSmutableArray 的实现原理机制
  6. baiduMap试手《办理进京证和市区警察查询进京证的地址浏览》
  7. 前端视频转码flv->swf
  8. Unity Shader常用函数,标签,指令,宏总结(持续更新)
  9. C++开发常见问题记录
  10. Scala 学习之路(十一)—— 模式匹配