0

I would like to serve the index.html file for my domain via a cdn (and a few other static pages).

Would it be possible to do this with an Amazon EC2 Instance and Rackspace Cloud Files?

I found something that sort of does this but only for an /images and /files directory:

server {
listen  80;
server_name cdn.failverse.com;
access_log /var/log/nginx/cdn.failverse.access.log;

location / {
   root /var/www/vhosts/domain2/public/cdn;
   index index.html;

    if  (!-e $request_filename)
       {
            rewrite ^/images/(.*)$  http://c0918182.cdn.cloudfiles.rackspacecloud.com/$1 redirect;
            rewrite ^/files/(.*)$ http://c0918176.cdn.cloudfiles.rackspacecloud.com/$1 redirect;

        }
      }
   }

http://failverse.com/using-your-own-domain-with-rackspace-cloud-files/

It would be great if I could have the Cloud Files be part of my own subdomains ie. cdn.mydocmain.com (If I have to use Rackspace Servers for everything that is okay too).

Thanks

  • Rackspace Cloud Files has CNAME support now--in fact you can simply create a CNAME for cdn.mydomain.com pointed to the domain of a CDN-enabled container, e.g., c0918182.r00.cdn.rackcdn.com--and that's it--you don't need to host servers with Rackspace or have any other service. Note that Cloud Files is a storage service, not a site delivery platform, so there is no concept of an index file (or automatically indexing a container to get a file list). If you want index.html, you have to request /index.html. – JCallicoat Aug 30 '11 at 19:55
  • Thanks MonkeeSage. That is exactly what I'm playing with now. I have CNAME setup right now but how would I tell ngnix to serve index.html and a javascript file directly from the cdn when a user goes to mydomain.com (so it serves cdn.mydomain.com/index.html when user requests mydomain.com). –  Sep 08 '11 at 18:00

1 Answers1

2

Well, there's no point in doing a redirect to a CDN (as per your example config), because by the time the request/response has gone through your server, and then the browser makes a new request to the CDN and gets the response, you could just have sent the client the darned content and been done with it. There's also issues with trying to do this with proxy CDNs that would be entertaining to work around in a robust fashion.

The typical way of utilising a CDN is that all of the static assets (images, JS, CSS) can be served out of a subdomain (like cdn.example.com) and the pages that users directly request contain the links to the CDN assets on the separate domain. It is far more rare (though not unknown) to try to serve everything out of a CDN, but if you do want to go that way, you really have to serve everything -- no dynamic content, nothing. The closest you can come is to have your dynamic content on one domain, and your static pages on the CDN, and link between them, but quite honestly, that way lies probable madness without a very good automated site build and distribution system.

womble
  • 95,029
  • 29
  • 173
  • 228
  • I understand why my request might be odd but I simply wanted to try to serve most of my content via cdn and then update via javascript as a test. – nobodytold Aug 28 '11 at 03:34