banner
二叉树树

二叉树树的xLog

Protect What You Love!
telegram
x
github
bilibili
steam_profiles
email

Cloudflare IP Optimization, making your website fully green!

This article is a remake of: https://xfeed.app/notes/71448-20


Not Optimized#

image

Optimized#

image


Conclusion: It can be seen that the response speed of the optimized websites has greatly improved, and the number of outbound IPs has also increased. This can significantly enhance the usability of your website and speed up loading times.
Optimized node used: cloudflare.182682.xyz

Let's Get Started!#

We need two domain names (for example: onani.cn and acofork.cn)

Here we will make onani.cn the primary domain and acofork.cn the secondary domain.


  1. First, create a DNS record pointing to your origin server, enable CF proxy
    image
  2. Go to SSL/TLS -> Custom Hostnames. Set the fallback origin to the domain of the DNS record you just created (xlog.acofork.cn), add the custom hostname as the domain you want users to access (onani.cn), and follow the instructions to add TXT ownership verification and TXT certificate verification to the primary domain (onani.cn) until the certificate status and hostname status both become valid.
    image
  3. Continue to add a record to your secondary domain. CNAME to the optimized node: cloudflare.182682.xyz, do not enable CF proxy
    image
  4. Finally, add a record to your primary domain. The domain is the custom hostname from the secondary domain (onani.cn), and the target is the previously mentioned cdn.acofork.cn, do not enable CF proxy
    image
  5. Optimization complete, try accessing it.

Optimization workflow: User accesses -> Since the final accessed domain has a CNAME record, it actually accesses cdn.acofork.cn, carrying origin hostname: onani.cn -> Reaches cloudflare.182682.xyz for optimization -> Optimization ends, CF edge node recognizes the carried origin hostname: onani.cn query and finds the fallback origin -> Falls back to the fallback origin content (xlog.acofork.cn) -> Access successful.


Troubleshooting#

  1. Q: What if my origin server uses Cloudflare Tunnels?
    A: You need to add two rules in Tunnels, one pointing to your secondary domain and one pointing to the final accessed domain. Then delete the DNS record for the final accessed domain (but do not delete it directly in Tunnels, as it will be removed from the whitelist, causing users to access 404). Then skip the first step.

Principle: Assume you have configured everything, but Cloudflare Tunnels only has one rule set.
Class discussion: If the rule you set only points to the secondary domain, then in the optimization workflow: User accesses -> Since the final accessed domain has a CNAME record, it actually accesses cdn.acofork.cn, carrying origin hostname: onani.cn -> Reaches cloudflare.182682.xyz for optimization -> Optimization ends, CF edge node recognizes the carried origin hostname: onani.cn query and finds the fallback origin -> Fallback origin detects origin hostname: onani.cn not in the whitelist -> Error 404 Not Found. Access failed.
Class discussion: If the rule you set only points to the final accessed domain, then in the optimization workflow: User accesses -> Since the final accessed domain has a CNAME record, it actually accesses cdn.acofork.cn -> Since cdn.acofork.cn is not in the Tunnels whitelist, access fails.


  1. Q: What if my origin server uses Cloudflare Origin Rule (port fallback)?
    A: You need to change the effective hostname of the rule to the final accessed domain; otherwise, the fallback policy will not be triggered (which will cause the secondary domain to be inaccessible, it is recommended to use Cloudflare Tunnels).

Principle: Assume you have configured everything, but the effective hostname of the Cloudflare Origin Rule (port fallback) is the secondary domain.
Then in the optimization workflow: User accesses -> Since the final accessed domain has a CNAME record, it actually accesses cdn.acofork.cn, carrying origin hostname: onani.cn -> Reaches cloudflare.182682.xyz for optimization -> Optimization ends, CF edge node recognizes the carried origin hostname: onani.cn query and finds the fallback origin -> Falls back to the fallback origin content (xlog.acofork.cn) -> But since origin hostname: onani.cn is not in the Cloudflare Origin Rule (port fallback) rules -> Cannot trigger the fallback policy, access fails.

  1. Q: What if my origin server uses serv00?
    A: You need to add two rules in the WWW Web Site interface, one pointing to your secondary domain and one pointing to the final accessed domain.

Principle: Assume you have configured everything, but serv00 only configured one of the domains.
Then in the optimization workflow: It will cause access errors, serv00 will intercept requests from domains not in the whitelist.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.