Saturday, 28 December 2013

Làm sao lấy IP thật connect tới server nếu bạn dùng cloudflare

Vấn đề đặt ra nếu server bạn đặt trước cloudflare.Thì ip connect đến server bạn sẽ là ip của cloudflare.Log ghi nhận cũng là ip cloudflare.Vậy để ghi log của người dùng thật bạn làm như sau.
Nếu dùng nginx edit file nginx.conf ở section http như sau
http {
set_real_ip_from   204.93.240.0/24;
set_real_ip_from   204.93.177.0/24;
set_real_ip_from   199.27.128.0/21;
set_real_ip_from   173.245.48.0/20;
set_real_ip_from   103.22.200.0/22;
set_real_ip_from   141.101.64.0/18;
set_real_ip_from   108.162.192.0/18;
real_ip_header     CF-Connecting-IP;

Nếu dùng Varnish trước nghinx thì sửa như vậy và add trên ip 127.0.0.1 vào danh sách như trên

http {
set_real_ip_from   204.93.240.0/24;
set_real_ip_from   204.93.177.0/24;
set_real_ip_from   199.27.128.0/21;
set_real_ip_from   173.245.48.0/20;
set_real_ip_from   103.22.200.0/22;
set_real_ip_from   141.101.64.0/18;
set_real_ip_from   108.162.192.0/18;
set_real_ip_from   127.0.0.1/32;
real_ip_header     CF-Connecting-IP;

Câu hỏi là mấy ip trên lấy ở đâu.Dễ lắm vào http://cloudflare.com/ips có gần đủ ip của cloudflare đó.Tất nhiên là ko đủ vì mình đã kiểm tra

No comments:

Post a Comment