Use a subfolder (path prefix) to serve Discourse with multiple servers sharing a domain

Discourse
Fri, 26 Jun 2015 20:57:34 +0000
Self-Hosting

Let’s say you have a WordPress blog on http://=DOMAIN=, and you want to serve your Discourse forums (which run on a different server) from http://=DOMAIN==PATH=. How do you do that?

Note: This won’t work for serving multiple Discourse instances from different folders on the same domain. You need to use different subdomains so that each site can have different cookies.

You’re going to need to send all traffic for the domain to one place that can route traffic to the correct server. In this how-to, I’ll use Fastly. So, Discourse will be running on one server, and the other parts of your site (like WordPress) will run on one or more other servers.

Docker container changes

First, follow the instructions here to serve Discourse from a subfolder.

Fastly

Now to setup Fastly to send traffic to the right place based on the path. I’ll assume that Discourse is being served from =PATH=.

Create a new service pointing to your main website and follow the instructions for updating your DNS settings.

Go to the service and click “Configure”. Make sure you have selected Version 2 so that you can make changes. Version 1 is the currently active version and can’t be changed.

In the “Hosts” section, add your Discourse server as a second backend.

In the Settings tab, add a new entry under Request Settings named “Discourse Pass” with action “Pass”.

Finally, for each host edit the conditions to specify where to route traffic.

For your main website, non-Discourse URLs should match.

req.url !~ "^=PATH="

For the Discourse host, =PATH= URLs should match.

req.url ~ "^=PATH="

1 messaggio - 1 partecipante