nginx同时写多个日志,获取访问的域名host

一、nginx.conf加自定义日志格式
  1. 带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"
#带host域名信息的日志格式
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"';
  1. 不带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"
#不带host域名信息的日志格式
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;
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值