Score:0

CDN CNAME resolves as the main host (how to restrict)

be flag

I recently created a CDN at StackPath. Everything works well, it serves files via a subdomain I created (cdn.mysite.com), which was created as a CNAME for the main site (CDN being the CNAME). However, while everything works well...I only need the CDN to serve the static files (images, css/js etc). The problem is, when I enter cdn.mysite.com in any browser, it shows the site www.mysite.com. To avoid duplicate issues with Google, I added a rel canonical to every page. Problem is, I've noticed that Google started to index some links as cdn.mysite.com instead of mysite.com.

Long story short, I don't want cdn.mysite.com to show as my site, but just to serve the static content, as I planned. I tried to restrict it from Apache, but it doesn't seem to work. Stackpath was "kind" enough to offer me a paid support tier for this advice, it wasn't enough that I paid for their service. Anyway, any help would be greatly appreciated.

Nikita Kipriyanov avatar
za flag
Express again in clear, *what* is your cdn CNAME is pointing at? And what CDN service documentation says about the target of the CNAME?
vexx avatar
be flag
the cname points at the root domain, mysite.com. It was a requisite for Stackpath to have a subdomain to use the CDN.
Nikita Kipriyanov avatar
za flag
"To have a subdomain **that points to your own server**" was the requirement? Are you sure? That is very, very strange. All name records point to your own servers, theirs are not involved. How **their** servers can possibly enter the play in this case? I expect CNAME should point to some *their* name, to the common name of their service that actually performs content distribution. Then, requests to your subdomain will be answered by their servers. That'll be logical. They should have been instructed you which name you should point your CNAME to.
vexx avatar
be flag
I appologize, I used the wrong words to explain it. Indeed, the CNAME points to the CDN stack (string.stackpath.com in my case). What I wanted to convey is that, while the CDN works, I don't want that cdn.mysite.com to work as a webpage. Currently, entering cdn.mysite.com in Chrome, it displays my site...and I'm worried for duplicate pages since Google already indexed my homepage as cdn.mysite.com instead of www.mysite.com.
Score:0
za flag

Create additional virtualhost on your server, for example, for-cdn.mysite.com. There you only publish assets that you want to distribute using CDN. Then configure the CDN to use that name as the source.

Additionally, you may disable indexing for that virtualhost using specific robots.txt. One usually doesn't want to index their assets and rather it is preferable to only index web pages that use these assets.

vexx avatar
be flag
Thank you for your answer. I already did that. I haven't used a robots.txt yet for the virtualhost, I just used rel canonical on all the pages to point to the main website. However, is there any way in which I can disable https://cdn.mysite.com to work (to return a 403/404) and just have the main site https://www.example.com to work in browsers. I just want https://cdn.example.com/images/* and https://cdn.mysite.com/css/* to work in serving the files from the cdn.
Nikita Kipriyanov avatar
za flag
You can't disable cdn.mysite.com to work. First of all, it is served by the CDN, not you; typically you can't configure their web server. Second, you *need* it to serve content to users, this is the purpose of the CDN after all. Ideally, it should only host big static assets and have indexing disabled, I mean, "indexes off", so it must return a resource by the direct link (which your site will be able to build), but not a list of hosted resources. Whether is this possible and how to do this, you really need to read in CDN's provider documentation; this is not a "common knowledge".
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.