Using Fastly to host a site in a subfolder?


Normally we host Discourse sites using a subdomain, e.g.

However we have a customer who wants

So we’re building out support for that. One thing we’ve run into is that this complicates the hosting scenario considerably, as

  • can point to a completely different IP address on our servers. This works great for hosting.

  • has to point to their domain. Not great for hosting. So this means either

    • we host their entire domain (not desirable for many reasons)

    • they proxy just the traffic in the /discourse folder to our server’s IP, which is complex and error prone for them.

We use Fastly as our CDN and have had great results with it, so we’re wondering, can we recommend they also purchase a Fastly plan, and use Fastly in front of their domain both as a CDN and as a proxy solution?

This would keep the complex proxying in the hands of third party experts (namely, Fastly), and we could share access to the Fastly credentials so we can both troubleshoot if something goes wrong.

Any tips for this kind of configuration, where you want to put a subfolder in control of a different IP address on the internet? Are there big price disparities if they need https vs http for this function?


This isn’t possible with DNS, unfortunately. I did see this option on StackOverflow, but it assumes that 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.


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?


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.


Just a quick note, got this working, one slight amendment is that I used the reverse rule for the other backend.


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
Site 2 is at a second host, and needs to be served at (but has a subdomain of 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 being served.

Is there any way to do this with Fastly?



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

There’s two things you can do:

  1. Add to the webserver configuration.
  2. Rewrite the Host header to a hostname it does like (i.e. 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.




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

Hope that didn’t confuse anyone.