Cloudflare 是如何处理HTTP Request Headers的(How Does Cloudflare handle HTTP Request headers)?

我们都知道,cloudflare其实本质上就是一个反向代理(reverse proxy), 因此cloudflare 会把收到的所有的HTTP headers request原原本本的转发给你的源服务器,在此基础上还会添加一些CF自己的header.

这些header 都有一个共同的特性,就是以CF开头

CF-Connecting-IP: 

Provides the client (visitor) IP address (connecting to Cloudflare) to the origin web server. 
This header will only be sent on the traffic from Cloudflare's edge to your origin webserver.

True-Client-IP (Enterprise plan only):

企业用户专享

X-Forwarded-For:

Maintains proxy server and original visitor IP addresses. If there was no existing X-Forwarded-For header in the request sent to Cloudflare, 
X-Forwarded-For has an identical value to the CF-Connecting-IP header

CF-RAY:

The cf-ray header is a hashed value encoding information about the data center and the visitor’s request

CF-IPCountry:

Contains a two character country code of the originating visitor’s country. XX is used for unknown country information

CF-Vistor:

Currently, this header is a JSON object, containing only one key called “scheme”. The meaning is identical to that of X-Forwarded-Proto above - e.g. it will be either HTTP or HTTPS, 
and it is only really relevant if you need to enable Flexible SSL in your Cloudflare settings.

CDN-Loop:

Allows Cloudflare to specify how many times a request can enter Cloudflare's network before it is blocked as a looping request.

CF-Worker:

The CF-Worker request header is added to an edge Worker subrequest that identifies the host that spawned the subrequest. 
This is useful when you want to protect against cross-zone worker subrequests.
You can add CF-Worker header on server logs similar to the way you add the CF-RAY header. Just add "$http_cf_worker" in the log format file: log_format cf_custom "CF-Worker:$http_cf_worker"'

用phpinfo()函数测试了一下,发现多了以下几个fields:

$_SERVER['HTTP_CDN_LOOP']: cloudflare
$_SERVER['HTTP_CF_CONNECTING_IP']: 99.99.99.99
$_SERVER['HTTP_CF_VISITOR']: {"scheme":"https"}
$_SERVER['HTTP_CF_RAY']: 6a4247906e83762b-EWR
$_SERVER['HTTP_X_FORWARDED_FOR']: 99.99.99.99
$_SERVER['HTTP_CF_IPCOUNTRY']: US

同时,REMOTE_ADDR这个ip是CF的节点IP

$_SERVER['REMOTE_ADDR']: 174.245.52.215 (CF新泽西IP)

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.