通过cloudflare header获得来源ip的国家

参考:https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-?flash_digest=56d9aa5823e170898758cad35230bc768c0f427e

https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-Cloudflare-IP-Geolocation-do-

在nginx.conf里定义log format:

log_format customlog '$http_cf_ipcountry' - '$http_cf_connecting_ip' - '$http_x_forwarded_proto' - '$http_cf_ray' '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' '"$request_time"';

access_log /var/log/nginx/access.log customlog;

然后访问 网站并查看日志:

TW-60.249.100.189-https-397a1234dsdf8538-HKG162.158.179.50 - - [11/Sep/2017:03:47:44 +0000] "GET / HTTP/1.1" 200 158 "https://www.lijiuyang.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "60.249.100.189""0.285"

 

打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注