Using Fastly to host a site in a subfolder?

Comments

6 comments

  • Austin Spires

    This isn't possible with DNS, unfortunately. I did see this option on StackOverflow, but it assumes that example.com is being served directly out of origin.

    The option you suggested -- working within your customer's Fastly account, is something that we've seen other organizations do before.

  • Sam Saffron

    By "working within fastly" I assume you just set up multiple backends and then use a rule to direct traffic to the correct origin. Is there an example config for this somewhere?

  • Austin Spires

    It's pretty easy, actually. You just add a second backend to the service, and set a conditional on the new backend like this:

    This will route all traffic matching the path /discourse to the Discourse backend.

  • emathy

    I have a use case pretty close to this, but I haven't quite figured out if or how it's possible.

    Site 1 is at one host, and needs to be served at http://www.example.com/ Site 2 is at a second host, and needs to be served at http://www.example.com/blog/ (but has a subdomain of blog.site.com for DNS purposes).

    I have no access, alas, to the web server configurations. The usual methods via mod_rewrite aren't available. I've played a bit with Fastly, and it seems like on the surface I could set up two backends (main, blog) and a conditional that looks for any ^/blog requests, sending those to the blog backend. The thing is, though, that method seems to be more of a redirect, sending those requests to the Blog backend results in blog.site.com/blog/ being served.

    Is there any way to do this with Fastly?

    Thanks!

  • Rogier Mulhuijzen

    What's probably happening is that your blog origin doesn't like the Host: www.example.com header, and serves the redirect.

    There's two things you can do:

    1. Add www.example.com to the webserver configuration.
    2. Rewrite the Host header to a hostname it does like (i.e. blog.example.com) in your Fastly config.

    Just add a Header object to set it, and put the same condition on it as you used for the origin selection.

    Cheers,

    Doc

  • Rogier Mulhuijzen

    Just to clarify, I changed from site.com to example.com, since that is what one is supposed to use in examples. :smile:

    Hope that didn't confuse anyone.

Please sign in to leave a comment.