Can multiple domains be linked to individual directories within a single S3 bucket on Fastly?
I want to host many websites from inside individual directories of a single S3 bucket and have them linked to three different domains on Fastly like so:
site-1.com => s3-us-west-2.amazonaws.com/my-bucket/site-1/index.html
site-2.com => s3-us-west-2.amazonaws.com/my-bucket/site-2/index.html
site-3.com => s3-us-west-2.amazonaws.com/my-bucket/site-3/index.html
...
site-n.com => some-bucket/site-n/index.html
I can do this using Cloudfront because its distributions support an additional path option which can route the request to the correct sub-directory inside the bucket. I don’t see a way to do this on Fastly and want to ask if anyone knows how this can be done?
-
@roman this is possible. For each URL path that you would want to rewrite, set up a new header rule like the following:
Then, with each new header rule, add a conditional like this:
What this does is do a swap of your bucket's root directory to
/path-you-define/
and then make sure that it only happens if the proper inbound host header is set. -
@aspires thanks I've been trying it but I'm having trouble setting the header
regexp
field. For some reason it is always ignored when I set it via the APIs:... condition = fastly_client.create_condition( :service_id => service.id, :version => latest_version_number, :name => 'host name condition', :priority => 10, :type => 'request', :statement => %Q(req.http.Host == "bucket-name.s3.amazonaws.com") ) ... header = fastly_client.create_header( :service_id => service.id, :version => latest_version.number, :name => 'path-on-s3-bucket', :ignore_if_set => false, :type => 'request', :dst => 'url', :src => 'req.url', :action => 'regex', :regexp => '^/', :substitution => '/sites/path/version/', :request_condition => condition.name )
The above produces this result: dl.dropboxusercontent.com/u/816353/Screen%20Shot%202015-03-24%20at%2012.04.44%20pm.png
Sorry I can't share photo links
-
@aspires never mind I figured out where things were going wrong:
The attribute name is not
regexp
it wasregex
. I was looking at lib/fastly/header.rb which confused the hell out of me. -
Hi.
I'm building a static site generator for a custom CMS.
We have potentially hundreds of clients/projects per client that need a custom domain name. eg: client-domain.com
We intend to use a single s3 bucket to host all the sites using sub-directories since s3 has a hard limit on buckets. staticsitesbucket/clientdomain.com/ staticsitesbucket/otherclient.net/
I've been testing fastly vcl rules a way do setup this type of behaviour without much success (I get 404s when accessing)
But I have other question as well. Does fastly provide a dedicated IP so that my clients can point their DNS CNAME's www.client_domain.com to fastly
And then I would create a rule to redirect www.client_domain.com to the respective s3 bucket directory.
Is this scalable to hundreds of domains pointing to a single backend?
Thanks.
-
[quote="serge, post:7, topic:316"] We intend to use a single s3 bucket to host all the sites using sub-directories since s3 has a hard limit on buckets.staticsitesbucket/clientdomain.com/staticsitesbucket/otherclient.net/
I've been testing fastly vcl rules a way do setup this type of behaviour without much success (I get 404s when accessing) [/quote]
It may make sense to file a support ticket so we can take a deeper look at your VCL for this.
[quote="serge, post:7, topic:316"] Does fastly provide a dedicated IP so that my clients can point their DNS CNAME's www.client_domain.com to fastly [/quote]
Yes, we do. But it's a little more complex. If you mention it in that same email to discuss your VCL we can go over it.
Please sign in to leave a comment.
Comments
6 comments