Trouble with subdomain.mysite.com proxy to mysite.com

I create a cname called subdomain with a target of mysite.com i would expect that when the user viisted subdomain.mysite.com it would display the contents from mysite.com, but it shows a connection timeout cloudflare page? any idea?
17 Replies
Chaika
Chaika15mo ago
What is the record on mysite.com pointing to? If it's Cloudflare pages you need to add your subdomain as another custom domain
Ricky U
Ricky UOP15mo ago
mysite.com cname is
mysite.pages.dev so the www.mysite.com and blog.mysite.com cannot cname to mysite.pages.dev?
Chaika
Chaika15mo ago
They can, but you need to every subdomain/domain (hostname), like blog.mysite.com, as another custom domain in your pages project custom domains tab
Chaika
Chaika15mo ago
Custom domains · Cloudflare Pages docs
When deploying your Pages project, you may wish to point custom domains (or subdomains) to your site.
Ricky U
Ricky UOP15mo ago
as an example in my dns i have this :
No description
Ricky U
Ricky UOP15mo ago
and www, works, i dont have any custom names for www. nor any redirects., no A records as well. so my thought is that if i have a cname like www2.domain.com that should workt too. but i get a host error ... is there something special with www? as i see under ssl the custom domains tab is empty.. i am also curisous why on pmgrouphk.com the www.pmgrouphk.com also works.. but for another domain i have www cname does not work unless i have a redirct set. so i should - remove the cname for all subdomains for www and other subdomains in the dns tab - add them to the custom domains tab do i need to add back any A records to 192.0.2.1 which i dont have any presentl presently do you mean under the ssl -> custom hostnames so i see the custom tabs, and i added test.mydomain.com and it work... when i go back to the dns , i see that a cname record was added to test pointing back to pages.dev... thats great, but why when i create the cname myself outside of the customs tab, it does not work..? what other setting could be added that i dont know about? understood, working on it.. effectively doesnt that just add the cname records for www to the pages.dev page? it works, but im wondering what is happening behind the scenes to the dns, i can see that it adds 2 cnames to dns.. which is pretty much what i had before, so something else is going on in pages..
Chaika
Chaika15mo ago
Pages uses CF for SaaS under the hood, and you need to explicitly allow hostnames (domains/subdomains) by adding them to Your Pages Custom Domains tab, otherwise they won't work. Cloudflare is in a sort of special position because they're both a cdn / in the middle of all requests, and also your host, but for normal DNS, a CNAME is just a "canonical redirect" to have DNS Resolvers follow to resolve the record they're looking for. The web server that receives the request has no idea about the CNAME existing or anything DNS level. If you tried to CNAME to pages.dev from a normal DNS point of view, you'd just be pointing at normal shared Cloudflare Proxy IPs. Web browsers would send the request to the IP with the host header of your website, and Cloudflare would just receive a request to a shared Proxy IP with the host header of: yoursubdomain.example.com, and any path/etc. That's not enough information to route it to the pages.dev, adding it as a Custom Domain in Pages adds the extra information about how requests by that host header should be handled.
Ricky U
Ricky UOP15mo ago
alright, i see. so in laymen terms, adding the apex and subdomain to the custom domain tabs effectilecy handles both the cname dns and the cf for saas settings.. why i brought all this up, is becuase i am actaully trying to add custom hostnames for my clients on their subdomains that would proxy to my pages site so now i am not sure where to do this in custom hostnames under ssl/tls or under the custom domains tab. so files.anothercompany.com -> pmgrouphk.com/xx
Chaika
Chaika15mo ago
Under Pages Custom Domains. You can't use Custom Hostnames directly with Pages without using something like a Worker script to proxy requests, you'd be trying to layer CF for SaaS on top of CF for SaaS
Ricky U
Ricky UOP15mo ago
can i use the api to create custom domans? i know for pro accounts there is a limit of 500 and 0.10 per additional domain is that right
Chaika
Chaika15mo ago
There's a public api for adding Pages Custom Domains here: https://developers.cloudflare.com/api/operations/pages-domains-add-domain The limits are here: https://developers.cloudflare.com/pages/platform/limits/ Pages Custom Domains are 250 for Pro per-project, with no ability to get more. Only Enterprise can get more then their set amount as far as I know.
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
Limits · Cloudflare Pages docs
Below are limits observed by the Cloudflare Free plan. For more details on removing these limits, refer to the Cloudflare plans page.
Ricky U
Ricky UOP15mo ago
thanks, since the limits for ent are only 500 as well, even while custom domains works, it may not be what were looking for... it may be the custom hostnames, however as you mentioned since we are using cf pages for our website hostnames isn't the solution for a pages project?
Chaika
Chaika15mo ago
sorry I may be being a bit confusing by mixing up terms: Custom Hostnames in your dashboard under SSL/TLS is equal to Cloudflare (CF) for SaaS. Pages itself uses CF for SaaS under the hood, so you can't directly use your own Custom Hostnames/CF for SaaS over it, you can think of it like both have an allowlist of host headers/websites, and so if you added a client to your website's custom hostnames/cf for saas config, the Page's Project's custon hostnames would reject it. You can use Pages Custom Domains up to their cap, and have your clients just CNAME to Pages.dev. Ent only has 500 to start with, but if they can get more by asking. Or, you can use a Worker Script that proxies the Pages Site and use Custon Hostnames/CF for SaaS directly, keeping in mind you'd be paying for worker invocations for each request
Ricky U
Ricky UOP15mo ago
okay got it (i think) i always assumed users of cf almost always used pages to host their website and everhting was intergrated, i.e. hostnames would work with pages etc.. if as you say cf for saas is used by pages itself i should then see the custom domains under the custom hostnames as well, but i dont... anyhow, for now i can use up the 250 - 500 or so using the api and ask my custoimers to add a simple cname for a subdomain. and set up a rule for adding paths params etc./ and if i go over 250, i can write a script to handle the rest hopefully.
Chaika
Chaika15mo ago
i always assumed users of cf almost always used pages to host their website and everhting was intergrated
Pages is relatively new, I believe if you're speaking to the whole userbase of Cloudflare, the vast majority use their own hosts and Wordpress.
if as you say cf for saas is used by pages itself i should then see the custom domains under the custom hostnames as well,
Your pages.dev is a zone in your account that you can't see, and the Custom Domains you add within your pages project are attached to it. (aka you just can't see them)
can use up the 250 - 500 or so using the api and ask my custoimers to add a simple cname for a subdomain. and set up a rule for adding paths params etc
That's pretty much the recommended approaches yea, using Pages Custom Domains directly up to their cap, or using a worker to proxy the pages site
Ricky U
Ricky UOP15mo ago
okay great, how then would i sort out the paths i.e. file.mycustomer.com/somepath/params -> pmgrouphk.com/somepath/params -- - use a page rule or bulk rediret or some sort? - also need to restrict file.mycustomer.com from going to my apex domain and only to their dashboard etc.
Chaika
Chaika15mo ago
What do you mean by sort out the paths? In that example, it seems the path would be same. If you need any sort of advanced logic, like customdomain.customer.com -> pages.dev/customername/path, that would usually be app-specific logic you would want to code in via a function, or potentially a second pages app specifically with customer app specific logic, not with redirects
Want results from more Discord servers?
Add your server