Subfolder Support

On the Business and Enterprise plans we support a so-called subfolder setup. Instead of running on its own hostname, Discourse will appear in a subdirectory of another host, for instance /forum or /community.

This makes the experience much more seamless, especially when you style your Discourse instance to closely match the look and feel of the rest of your website.

However, this setup is more complex and takes some effort to configure. The configuration on our side and on your side need to happen at the same time since putting your forum into subfolder mode will render it unaccessible by any other means.

For the configuration on our side, we need to know the following:

  • the hostname you will be using;
  • the subdirectory name you will be using;
  • the IP address(es) of the server(s) running the remainder of your website (or if you’re using a service like Cloudfront or Cloudflare, we need to know that).

On your side you need to set up a reverse proxy configuration that applies to the subdirectory and anything ‘within’ it.

You need to take care of two things there:

  • You need to forward the actual host name to the forum – after all, the forum needs to use that in order to recognise the traffic;
  • You need to address the forum by its discoursehosting.net hostname, because you cannot address it by the external hostname – that would create an endless loop since it points to the server containing the reverse proxy.

Example setup for nginx

If you’re running nginx on your main website, then you can use the following snippet in your configuration:

location /SUBDIRECTORY {
    proxy_pass https://YOURFORUM.discoursehosting.net;
    proxy_set_header Host "WWW.YOURDOMAIN.COM";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

You need to replace the capitalized text with your specific configuration.

The configuration on our side is done outside of the control panel, so you need to contact our support for it.

Example setup using Apache 2

If you’re running nginx on your main website, then you can use the following snippet within your VirtualHost configuration:

SSLProxyEngine on
SSLProxyCheckPeerName off
ProxyPreserveHost On
ProxyPass "/SUBDIRECTORY" "https://YOURFORUM.discoursehosting.net/SUBDIRECTORY"

You need to replace the capitalized text with your specific configuration.

The configuration on our side is done outside of the control panel, so you need to contact our support for it.

Example setup using Cloudflare Workers

If your main website is behind Cloudflare, you can use a Worker to proxy the subdirectory to your forum.

Create a worker with the following code and configure it at www.example.com/forum* (note the asterisk at the end!) where www.example.com is the name of your main website and forum is the subdirectory you are mounting your forum at.

addEventListener("fetch", (event) => {
  event.respondWith(
    handleRequest(event.request).catch(
      (err) => new Response(err.stack, { status: 500 })
    )
  );
});

async function handleRequest(request) {
  const url = new URL(request.url);
  request = new Request(request)
  request.headers.set("CF-Host", url.hostname)
  url.hostname = 'YOURFORUM.discoursehosting.net';
  return fetch(url.toString(), request)
}

You need to replace the capitalized text with your specific configuration.

Because Cloudflare does not allow replacing the Host header of a request for security reasons, we marshal the original host into the request using a CF-Host header.

There is no need to set up X-Forwarded-For since Cloudflare does this automatically.

When setting up Cloudflare, make sure you’ve read our knowledge base article so you can avoid all the caveats!

The configuration on our side is done outside of the control panel, so you need to contact our support for it.