ngx_http_log_module 模块负责日志:
=======默认nginx日志
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
效果1:
192.168.11.12 - - [01/Feb/2018:10:12:05 +0800] "HEAD /ss HTTP/1.1" 200 0 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2"
========自定义nginx日志
log_format access '$remote_addr - "$host" "$hostname" [$time_local] '
'"$request" $status $bytes_sent $body_bytes_sent $request_time '
'"$http_referer" "$http_user_agent" $server_addr '
'"$http_range" $upstream_response_time "$upstream_addr" $upstream_status $upstream_http_Isure_Upstream_Time';
效果1:
192.168.11.12 - "www.web2.com" "dev-2" [01/Feb/2018:10:36:54 +0800] "GET /ss/gskhsk HTTP/1.1" 200 235 39 0.001 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2" 192.168.11.12 "-" 0.001 "127.0.0.1:9000" 200 -
效果2:
192.168.11.188 - "www.web2.com" "dev-2" [01/Feb/2018:10:40:42 +0800] "GET http://www.web2.com/ss/gskhsk HTTP/1.1" 200 235 39 0.001 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh3/1.4.2" 192.168.11.12 "-" 0.001 "127.0.0.1:9000" 200 -
配置:
access_log /logs/nginx/access.log access;
log_format格式变量:
$remote_addr #记录访问网站的客户端地址
$remote_user #远程客户端用户名
$time_local #记录访问时间与时区
$request #用户的http请求起始行信息
$status #http状态码,记录请求返回的状态码,例如:200、301、404等
$body_bytes_sent #服务器发送给客户端的响应body字节数
$http_referer #记录此次请求是从哪个连接访问过来的,可以根据该参数进行防盗链设置。
$http_user_agent #记录客户端访问信息,例如:浏览器、手机客户端等
$http_x_forwarded_for #当前端有代理服务器时,设置web节点记录客户端地址的配置,此参数生效的前提是代理服务器也要进行相关的x_forwarded_for设置
测试: curl -I "http://web2.com?name=yeqing&age=18" -x 192.168.11.12:80
注意:自定义完日志 需要 service nginx restart
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。