Nginx日志配置整理

环境介绍:
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地址

--先整理这么多。。。。。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值