配置示例
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
log_format 指令
默认值:log_format combined "...";
标签段位置:http
常用变量:
- $bytes_sent 发送给客户端内容的字节数,位于ngx_http_log_module
- $request_length 请求长度(包括请求行,标头和请求正文),位于ngx_http_log_module
- $request_time 要求以毫秒为单位的处理时间,位于ngx_http_log_module
- $status 状态码,位于ngx_http_log_module
- $time_local 请求的本地时间和市区,位于ngx_http_log_module
- $remote_addr 客户端地址,位于ngx_http_core_module
- $remote_user Basic授权模式下的客户端用户名称,位于ngx_http_core_module
- $request 完整的请求地址和协议,位于ngx_http_core_module
- $request_body 请求的body内容,位于ngx_http_core_module
- $http_host 域名或IP
- $http_referer 请求的跳转来源
- $http_user_agent 浏览器信息
- $http_x_forwarded_for 记录客户端地址的配置
如果变量对应的值不存在,则以“-
”代替。
access_log 指令
默认值:access_log logs/access.log combined;
标签段位置:http
, server
, location
, if in location
, limit_except
access_log off;
access_log logs/access.log main;
access_log logs/access.log main buffer=32k flush=5s;
map $status $loggable {
~^[23] 0;
default 1;
}
# 非2xx 和 3xx 的状态才写入日志
access_log /path/to/access.log main if=$loggable;
重载配置
../sbin/nginx -t
../sbin/nginx -s reload
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。