Piwik获取访客真实的IP地址

by Web全栈工程师 on 2013 年 12 月 18 日

我们用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代码,即可。

Comments on this entry are closed.

Previous post:

Next post: