我用的是lnmp.org的环境

/usr/local/nginx/conf/nginx.conf

    http {

    }

部分增加

map $HTTP_CF_CONNECTING_IP  $clientRealIp {
    ""    $remote_addr;
    ~^(?P<firstAddr>[0-9.]+),?.*$    $firstAddr;
}
log_format  main  '$clientRealIp [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '$http_user_agent $remote_addr $request_time';

主要是为了通用性,如果关闭了CDN,可以不需要修改获取IP的方式,所以才这么修改,不然直接用$HTTP_CF_CONNECTING_IP就行了(这个时候就不需要在日志格式里使用$clientRealIp)

然后在网站记录的日志定义使用main这个日志格式

比如

access_log /home/wwwlogs/abc.com.log main;

参考来源:https://www.bnxb.com/php/27592.html

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2021-10-26
  • 2021-04-20
  • 2021-12-25
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-02-23
  • 2022-02-14
  • 2021-12-06
相关资源
相似解决方案