Cloudflare CDN 如何实现自定义源站端口、代理、端口转发任何协议

  根据官方参考文章内容“Which ports will Cloudflare work with?”所述,Cloudflare 支持以下方式的自定义端口访问。

  首先在 DNS 解析处正常添加解析记录,然后访问的时候支持这样:

HTTP 流量可以使用的回源端口

1
2
3
4
5
6
7
http://lcx.cc:80 --> http://源服务器地址:80
http://lcx.cc:8080 --> http://源服务器地址:8080
http://lcx.cc:8880 --> http://源服务器地址:8880
http://lcx.cc:2052 --> http://源服务器地址:2052
http://lcx.cc:2082 --> http://源服务器地址:2082
http://lcx.cc:2086 --> http://源服务器地址:2086
http://lcx.cc:2095 --> http://源服务器地址:2095

HTTPs 流量可以使用的回源端口

1
2
3
4
5
6
https://lcx.cc:443 --> https://源服务器地址:443
https://lcx.cc:2053 --> https://源服务器地址:2053
https://lcx.cc:2083 --> https://源服务器地址:2083
https://lcx.cc:2087 --> https://源服务器地址:2087
https://lcx.cc:2096 --> https://源服务器地址:2096
https://lcx.cc:8443 --> https://源服务器地址:8443

  即:访问的前后端都加特定的端口,成对访问。

  需要注意的是,由于众所周知的备案问题,CloudFlare 对外提供服务的端口在企业用户开启使用大陆 CDN 节点的情况下(备案后),就只能使用 80、443 端口,也就是说中国境内的 HTTP/HTTPS 流量节点只支持 80 和 443 端口

  同时 Cloudflare 还新出了一个端口转发服务Proxy Anything,目前是免费的,需要申请试用,支持转发任何协议、任何数据(目前仅开放了 TCP 协议),具体如何申请参考底下

  So,掌握了这些,你就可以将 V2Ray、Shadowsocks(ShadowsocksR/SS/SSR/酸酸乳)游戏服务器等服务架设在 Cloudflare 高速 CDN 网络上,还能隐藏原始 IP 地址防止被封,你懂的……

  那么还有个问题是,这样自定义端口的方式,访客访问的时候会很不方便,总不能让访客每次都手工输入端口号吧?而且这玩意也不好记……

  其实,Cloudflare 已经帮我们解决这个问题了,这个功能就是:页面规则(Page Rules)

  通过自定义页面规则,可以在访客输入不带端口的主域名 https://lcx.cc/ 的时候自动跳转到 https://lcx.cc:自定义端口/,实现无感知访问跳转,不用手动输入自定义的端口了,比较方便

  例如创建以下页面规则

  规则:lcx.cc:80/*

  类型:转发 URL,301 永久重定向

  目标:https://lcx.cc:8080/$1

  注意:HTTPS 网站建议开启“Always Use HTTPS”。

  具体用法请参考官方说明文档:了解和配置 Cloudflare Page Rules 页面规则教程

参考资料

  1、CloudFlare上线了新的Proxy Anything选项, 支持转发TCP连接

可以说是期待了一段时间的Cloudflare的TCP转发功能算是上线了,固定了TCP端口(我看到的反正是43和44),并支持HAProxy所支持的PROXY v1协议,已测试可爱的V2Ray/Shadowsocks都能使用,并且延迟和带宽都还不错(此处仅指我本地测试结果).

设置很简单,不多说什么了,大家自己去用用看.

另外,恕鄙人不靠谱预测一下,从选端口的时候同时选协议并且选项叫protocol,以及申请表单标题是L4 Proxy看,应该后续有udp支持.

补一个说明:本人绝对的免费用户,如果你没看到proxy anything的选项应该是先前没有提交试用表单.

申请地址: https://goo.gl/forms/Oc2jyyo0kXsrMyw33

设置指南: https://docs.google.com/document/d/1jXdmDH8QBg1OQEG5Mb18jYjoPg-XJRuls4IdnyBofLw/edit?usp=sharing

论坛反馈: https://community.cloudflare.com/t/proxy-anything-beta-feedback/11112

  2、Which ports will Cloudflare work with?

Cloudflare将与哪些端口配合使用?

Cloudflare代理应用程序级别(第7层)的HTTP流量和传输级别(第4层)的TCP流量的流量。

概观

  Cloudflare几乎可以代理所有TCP端口。我们支持两种代理:

  应用程序级别(第7层)HTTP代理,以及   频谱,传输级别(第4层)TCP代理

HTTP代理

  Cloudflare可以代理通过下面列出的HTTP / HTTPS端口的流量。

  如果您的流量位于不同的端口,则可以将其作为我们不代理的内容添加为Cloudflare DNS区域文件中的记录(灰色云=没有Cloudflare代理或记录缓存)。

  Cloudflare支持的HTTP端口是:

  80,8080,8880,2052,2082,2086,2095

  Cloudflare支持的HTTPs端口是:

  443,2053,2083,2087,2096,8443

对于Pro计划及更高版本,您可以使用WAF规则ID 100015阻止80和443以外的端口上的流量:“阻止对除80和443之外的所有端口的请求”。

端口80和443是唯一的端口:

  对于启用了中国网络的区域内的中国境内的HTTP / HTTPS流量   对于Cloudflare应用程序能够代理   当CloudFlare的缓存可用

频谱代理

  Cloudflare Spectrum是一种企业计划产品,支持通过任何端口代理任意TCP协议。唯一的例外是端口21,其中不支持代理。

  要了解更多信息,请访问Cloudflare Spectrum文档站点。

以下是英文原文

Cloudflare proxies traffic for HTTP traffic at the application level (Layer 7) and TCP traffic at the transport level (Layer 4).

Overview

  Cloudflare can proxy almost all TCP ports. We support two flavors of proxy:

  an application level (Layer 7) HTTP proxy, and   Spectrum, a transport level (Layer 4) TCP proxy

HTTP proxying

  Cloudflare can proxy traffic going over the HTTP/HTTPS ports listed below.

  If your traffic is on a different port, you can add it as a record in your Cloudflare DNS zone file as something we don’t proxy (gray cloud = no Cloudflare proxy or caching on a record).

  The HTTP ports that Cloudflare support are:

  80,8080,8880,2052,2082,2086,2095

  The HTTPs ports that Cloudflare support are:

  443,2053,2083,2087,2096,8443

  For the Pro plan and above, you can block traffic on ports other than 80 and 443 using WAF rule id 100015: “Block requests to all ports except 80 and 443”.

  Ports 80 and 443 are the only ports:

  For HTTP/HTTPS traffic within China for zones that have the China Network enabled   For Cloudflare Apps to be able to proxy on   Where Cloudflare Caching is available

Spectrum proxying

  Cloudflare Spectrum is an Enterprise plan product that supports proxying arbitrary TCP protocols over any port. The only exception is port 21, where proxying is not supported.

To learn more, visit the Cloudflare Spectrum documentation site.