Nginx日志配置整理
2015-05-16 13:09
661 查看
环境介绍:
OS:CentOS 6.X
Nginx版本:1.4.7以上
打印Nginx日志,对于排查错误必不可缺!
因为Nginx基本都是由模块控制的,参考链接:http://nginx.org/en/docs/http/ngx_http_log_module.html
Nginx日志相关的配置如access_log、error_log、log_format、open_log_file_cache、log_not_found、log_subrequest、rewrite_log。
这时得赞一下Nginx的日志管理模式:每个级别的配置可以有各自独立的访问日志。日志格式通过log_format命令来定义。
1. access_log指令
参考链接:http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
语法: access_log path [format [buffer=size [flush=time]]];
access_log path format gzip[=level] [buffer=size] [flush=time];
access_log syslog:server=address[,parameter=value] [format];
access_log off;
默认值: access_log logs/access.log combined;
配置段: http, server, location, if in location, limit_except
2. error_log指令
参考链接:http://nginx.org/en/docs/ngx_core_module.html#error_log
语法: error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];
默认值: error_log logs/error.log error;
配置段: main, http, server, location
配置错误日志。
默认为crit,可根据需求调整,我指定为error
3. log_format指令
语法: log_format name string …;
默认值: log_format combined “…”;
配置段: http
#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 记录客户端IP地址
$remote_user 记录客户端用户名称
$time_local 通用日志格式下的本地时间。
$request 记录请求的URL和HTTP协议
$status 记录请求状态
$body_bytes_sent 发送给客户端的字节数,不包括响应头的大小;
$http_referer 记录从哪个页面链接访问过来的
$http_user_agent 记录客户端浏览器相关信息
$http_x_forwarded_for 记录客户端IP地址
--先整理这么多。。。。。
OS:CentOS 6.X
Nginx版本:1.4.7以上
打印Nginx日志,对于排查错误必不可缺!
因为Nginx基本都是由模块控制的,参考链接:http://nginx.org/en/docs/http/ngx_http_log_module.html
Nginx日志相关的配置如access_log、error_log、log_format、open_log_file_cache、log_not_found、log_subrequest、rewrite_log。
这时得赞一下Nginx的日志管理模式:每个级别的配置可以有各自独立的访问日志。日志格式通过log_format命令来定义。
1. access_log指令
参考链接:http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
语法: access_log path [format [buffer=size [flush=time]]];
access_log path format gzip[=level] [buffer=size] [flush=time];
access_log syslog:server=address[,parameter=value] [format];
access_log off;
默认值: access_log logs/access.log combined;
配置段: http, server, location, if in location, limit_except
2. error_log指令
参考链接:http://nginx.org/en/docs/ngx_core_module.html#error_log
语法: error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];
默认值: error_log logs/error.log error;
配置段: main, http, server, location
配置错误日志。
默认为crit,可根据需求调整,我指定为error
3. log_format指令
语法: log_format name string …;
默认值: log_format combined “…”;
配置段: http
#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 记录客户端IP地址
$remote_user 记录客户端用户名称
$time_local 通用日志格式下的本地时间。
$request 记录请求的URL和HTTP协议
$status 记录请求状态
$body_bytes_sent 发送给客户端的字节数,不包括响应头的大小;
$http_referer 记录从哪个页面链接访问过来的
$http_user_agent 记录客户端浏览器相关信息
$http_x_forwarded_for 记录客户端IP地址
--先整理这么多。。。。。
相关文章推荐
- Nginx 基本配置和日志分析
- 实现Nginx中使用PHP-FPM时记录PHP错误日志的配置方法
- nginx 配置日志
- nginx日志配置
- nginx前端,tomcat后端服务器获取客户的真实IP,包括tomcat访问日志获取真实IP的配置
- Nginx日志配置
- nginx中用JSON格式记录日志的配置示例
- nginx日志配置
- nginx 配置日志
- nginx的日志配置
- nginx日志配置详解 -----谷营中西软件科技园
- Nginx演练(2)配置日志访问
- nginx 直接在配置文章中设置日志分割
- nginx1.10.3一键安装/系统内核优化/配置文件优化/https/日志切割
- Nginx日志配置与切割
- 配置 Nginx日志相关信息
- nginx服务器access_log日志分析及配置详解
- Nginx日志配置及配置调试
- Nginx实战(三) 日志配置与切割
- nginx+keepalived安装配置(整理中)