This article is a remake of: https://xfeed.app/notes/71448-20
Not Optimized#
Optimized#
Conclusion: It can be seen that the response speed of 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.
- First, create a new DNS record pointing to your origin server, enable cf proxy
- Go to SSL/TLS -> Custom Hostnames. Set the fallback origin to the domain of your newly created DNS record (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.
- Continue to add a record to your secondary domain. CNAME to the optimized node: cloudflare.182682.xyz, do not enable cf proxy
- Finally, add a record to your primary domain. The domain should be the custom hostname from the secondary domain (onani.cn), and the target should be the earlier mentioned cdn.acofork.cn, do not enable cf proxy
- Optimization is complete, try accessing it.
Optimization workflow: User accesses -> Since the final access domain has a CNAME record set, 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 content (xlog.acofork.cn) -> Access successful.
Troubleshooting#
- 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 access domain. Then delete the DNS record for the final access domain (but do not delete it directly in Tunnels, as it will drop the whitelist and cause 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 access domain has a CNAME record set, 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 is not in the whitelist -> Error 404 Not Found. Access failed.
Class discussion, if the rule you set only points to the final access domain, then in the optimization workflow: User accesses -> Since the final access domain has a CNAME record set, it actually accesses cdn.acofork.cn -> Since cdn.acofork.cn is not in the Tunnels whitelist, access fails.
- 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 access 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 access domain has a CNAME record set, 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 content (xlog.acofork.cn) -> But since origin hostname: onani.cn is not in the Cloudflare Origin Rule (port fallback) rules -> The fallback policy cannot be triggered, access fails.
- 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 access 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 for domains not in the whitelist.