0

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.

vexx
  • 11
  • 2
  • Express again in clear, *what* is your cdn CNAME is pointing at? And what CDN service documentation says about the target of the CNAME? – Nikita Kipriyanov Aug 23 '23 at 16:21
  • the cname points at the root domain, mysite.com. It was a requisite for Stackpath to have a subdomain to use the CDN. – vexx Aug 23 '23 at 16:57
  • "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. – Nikita Kipriyanov Aug 24 '23 at 03:31
  • 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. – vexx Aug 24 '23 at 09:33

1 Answers1

0

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.

Nikita Kipriyanov
  • 10,947
  • 2
  • 24
  • 45
  • 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. – vexx Aug 25 '23 at 09:26
  • 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". – Nikita Kipriyanov Aug 25 '23 at 11:09