• Welcome to LiuJason's Blog!

CloudFlare传递真实ip 缓存文件同时不缓存HTTP header|301 302重定向等

Web项目 Jason 5 years ago (2019-03-11) 1248 Views 0 Comments QR code of this page

1、CloudFlare缓存文件的同时不缓存HTTP header

前几天搞的aff.mx网址缩短服务套了CF,然后好像大部分点击量是直接CF做301跳转的,这样统计不到真实的点击量。
所以希望能在隐藏源服务器ip的同时,能传递访问请求(注意这里不是不缓存文件,是不缓存301定向)。

Page Rules对301、302这种header信息有效,但是不能直接设定,具体可以看这里:https://aff.mx/MfAkz
也就是说page rules只能让CF知道要不要缓存页面中的静态文件,但是一旦选择缓存文件那么http头部的返回值他们是会默认缓存的。
【除非】:在源网页的头部中就有写Cache-Control: private, no-cache or public, max-age=0 (or some combination)

问题的解决方案:在网页上添加no-cache参数就好~

 

2、传递真实ip

在Nginx规则里添加如下参数即可:

set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;

# use any of the following two
real_ip_header CF-Connecting-IP;
#real_ip_header X-Forwarded-For;

参考官方文档 https://aff.mx/wIhmO


This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/235.html
Like (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址