配置示例
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://nginx.org/en/docs/http...
http://nginx.org/en/docs/http...