Can multiple domains be linked to individual directories within a single S3 bucket on Fastly?

Comments

6 comments

  • Austin Spires

    @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.

  • Austin Spires

    Yes. Everything in the Fastly app is build API-first, so you can use API calls to make these changes.

  • Arman Mirkazemi

    @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

  • Arman Mirkazemi

    @aspires never mind I figured out where things were going wrong:

    The attribute name is not regexp it was regex. I was looking at lib/fastly/header.rb which confused the hell out of me.

  • serge

    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.

  • Austin Spires

    [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.