一、nginx.conf加自定义日志格式
- 带host域名信息的日志
121.69.18.90 - - [01/Jul/2022:10:29:13 +0800]"GET http://t-test.cn/app/common/config?sign=7f7292411e364ebe167375bfda2e5315491ab040e0e1300a27f52ce7e2b01306 HTTP/1.1" 200 918 "-" "PostmanRuntime/7.26.5" "-" - "0.022"
log_format main_host '$remote_addr - $remote_user [$time_local]'
'"$request_method $scheme://$host$request_uri $server_protocol" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" - "$request_time"';
- 不带host域名信息的日志
121.69.18.90 - - [01/Jul/2022:10:25:25 +0800] "GET /app/common/config?sign=7f7292411e364ebe167375bfda2e5315491ab040e0e1300a27f52ce7e2b01306 HTTP/1.1" 200 84 "-" "okhttp/3.12.0" "-" - "0.017"
log_format main_test '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" - "$request_time"';
二、具体的server里加access_log,可以同时加多条
access_log /home/accesslogs/main_test.log main_test;
access_log /home/accesslogs/main_host.log main_host;