我们用piwik统计访客的时候,可能会遇到访客IP都是同一个IP地址的情况,其实这是因为有些CDN或者ISP会隐藏访客HTTP请求里Header信息,我们只要修改piwik的配置文件就可以了。
打开piwik的配置文件 ./config/global.ini.php,查看相关代码
; Set to 1 if you're using https on your Piwik server and Piwik can't detect it, ; e.g., a reverse proxy using https-to-http, or a web server that doesn't ; set the HTTPS environment variable. assume_secure_protocol = 0 ; List of proxy headers for client IP addresses ; ; CloudFlare (CF-Connecting-IP) ;proxy_client_headers[] = HTTP_CF_CONNECTING_IP ; ; ISP proxy (Client-IP) ;proxy_client_headers[] = HTTP_CLIENT_IP ; ; de facto standard (X-Forwarded-For) ;proxy_client_headers[] = HTTP_X_FORWARDED_FOR ; List of proxy headers for host IP addresses ; ; de facto standard (X-Forwarded-Host) ;proxy_host_headers[] = HTTP_X_FORWARDED_HOST ; List of proxy IP addresses (or IP address ranges) to skip (if present in the above headers). ; Generally, only required if there's more than one proxy between the visitor and the backend web server. ; ; Examples: ;proxy_ips[] = 204.93.240.* ;proxy_ips[] = 204.93.177.0/24 ;proxy_ips[] = 199.27.128.0/21 ;proxy_ips[] = 173.245.48.0/20 ; Whether to enable trusted host checking. This can be disabled if you're running Piwik ; on several URLs and do not wish to constantly edit the trusted host list. enable_trusted_host_check = 1
一般不建议修改global.ini.php,打开./config/config.ini.php,添加相关的proxy_client_headers代码,即可。
原创文章,转载请注明:转载自Web开发笔记 | Piwik获取访客真实的IP地址
本文链接地址:https://www.magentonotes.com/piwik-get-client-ip-address.html
Comments on this entry are closed.