How to Configure CDN for Discourse with StackPath

Photo of author

By Victor Ashiedu

Published

Do you want to configure StackPath CDN for your Discourse forum but couldn’t find any comprehensive guide? I had the same problem, so I created this step-by-step guide.

Step 1: Create a StackPath Account

As I mentioned in my introduction, the first step to configuring StackPath CDN for your Discourse forum is to create a StackPath account. Then, create your StackPath “Site”.

Follow the steps below to complete these tasks:

  1. Open stackpath.com and create an account. To create an account, on the top right of the stackpath.com homepage, click Get Started.
The fastest way to create an account with StackPath is to scroll down the Get Started page and sign in with either your GitHub, Google or Facebook accounts.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
  1. Once you have created a StackPath account, control.stackpath.com. Then, on the top right of your StackPath Dashboard, click Create Site.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
  1. On the Create a Site // Select an Integration page, click Select Full Site.
  1. On the Create a Site // Full Site Integration page, enter the URL of your Discourse forum. In this example, I am using the URL of Itechguides Community forum, community.itechguides.com.
  2. After entering the URL, check the box beside the Content Delivery Network (CDN) option, scroll down and click Add to subscription.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
  1. When you click the Add to subscription button, StackPath will require you to confirm the subscription. When I published this article, StackPath was charging $25/m for this service.

    If you wish to continue, click Continue. It will take a few seconds for this stage to complete. Once completed, proceed to step 7 below.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
I was not prompted to add billing information here because I already did that. You may be prompted to add your credit card at this stage.
  1. To proceed to the next step, click Set Up Your Origin.
  1. On the next page, StackPath will display the IP address of your Discourse forum in the “Origin Hostname / IP Address” field. Confirm that it is the correct IP address.

    Then, scroll down to the “Do you want to add a custom domain (for example, cdn.yourdomain.com)?” and select Yes. When you select Yes, the Confirm Origin Address button will change to Add Delivery Domains.
  2. To proceed to the next step, click Add Delivery Domains.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
  1. When the Add Delivery Domains page opens, your Discourse forum (added earlier) will be displayed.

    Beneath your Discourse forum’s URL, add your CDN subdomain. Then, click the Add button.
  2. Once your CDN subdomain has been added, click Confirm Delivery Domains.
Most people simply add “-CDN” to the subdomain of their Discourse forum URL. In this example, I am using community-cdn.www.itechguides.com.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
  1. Then, on the “Select an SSL Method (Optional)” page, accept the defaults. Then, scroll down and click Accept SSL Method.
How To Configure CDN For Discourse With StackPath - How To Create A StackPath Account And Configure Your StackPath "Site"
  1. Once you click Accept SSL Method, the Validate with DNS Challenge page will be displayed. You will use the information displayed here to validate your ownership of your Discourse forum URL domain.

    You will complete this task in the next section.

Step 2: Verify Domain Ownership

This is the next step to configuring CDN for your Discourse forum is to verify your domain.

In this example, I am updating the DNS record for Cloudflare. You should be performing this task where your domain’s DNS record is managed.
  1. Login to your DNS provider’s site, locate manage DNS and click Add. If you use Cloudflare, log in to Cloudflare, then, open your active domain hosted by Cloudflare.
This is the next step to configuring CDN for your Discourse forum is to verify your domain.
  1. Then, on the left pane of the left pane, click DNS.
  1. On the DNS management page for your domain, create two CNAME entries – one for your CDN domain, and the second for the forum domain. In my example, community.itechguides.com, and community-CDN.www.itechguides.com.
  1. Back to your StackPath setup page, expand the “Validate with HTTP Request” section. Then, in your DNS provider, create a CNAME record for your CDN domain.

    Use the information provided by StackPath.
Before you can create a CNAME for your forum’s subdomain (in my example, “Community.www.itechguides.com”), you must delete the existing A record for the same subdomain in your DNS entry.

If you use Cloudflare, make sure to turn Proxy status off.
  1. Still, on the StackPath website, scroll down and check “I have completed one of the above validation steps to verify I own the domain.”. Then, click Verify Domain Ownership.
  1. Once StackPath has verified that you own the primary domain, it will display the information you require to Update Your DNS.
  2. Open the DNS management on your DNS provider’s page and create the A record. StackPath will display the information you require on the Update Your DNS page.
DO NOT add the A record to point to your root domain as shown by StackPath in the screenshot below. Rather, instead of using @ for the name of the A record, use the sub-domain name for your Discourse forum URL. In my example “community”.
You do not need to create the CNAME record. I am not sure why StackPath is requesting for these two records to be created. All you need is to create the CNAME record for the CDN domain (which you’ve already done in step 3 above). Then, in step 7, you have added an A record for your Discourse forum URL subdomain.

There is one more step to complete the configuration of CDN for Discourse with StackPath. See the next section for details.
  1. Finally, check the “I have completed the above steps to point my DNS to StackPath.” box. Then, click Complete Setup.
Before you proceed to the next step, click EdgeSSL. Then, confirm that StackPath has successfully issued your domains a free SSL certificate. Finally, turn “Force HTTPS Connections” ON.

Step 3: Update your Discourse App.yml

This is the final stage to configure CDN for Discourse with StackPath.

  1. SSH to your Discourse host server. Then, run the commands below. The second command will open your Discourse app.yml file for editing.
cd /var/discourse
nano containers/app.yml
  1. When the app.yml opens, uncomment the CDN line and update it with the CDN CNAME you set up in your DNS. Before you uncomment the CDN line, it will look like the highlighted portion of the screenshot below.
Update Your Discourse App.yml File With The StackPath CDN Entries
  1. Now, remove # in front of DISCOURSE_CDN_URL: https://discourse-cdn.example.com and change “https://discourse-cdn.example.com” to your CDN URL. When you finish, the CDN line will look like this:
DISCOURSE_CDN_URL: https://community-CDN.www.itechguides.com
Chnage https://community-CDN.www.itechguides.com to your CDN domain URL.
Update Your Discourse App.yml File With The StackPath CDN Entries
  1. When you’re happy with the changes to the app.yml, pres Ctrl and X keys on your keyboard simultaneously. Then, app.yml will prompt you to save the file – type Y and press enter.
  2. Finally, to rebuild your Discourse container for the changes you made to take effect, run the two commands below.
cd /var/discourse
./launcher rebuild app
Update Your Discourse App.yml File With The StackPath CDN Entries
  1. Wait for Discourse to complete the container rebuild. Then, to confirm that your static assets are now served via the CDN, open your forum in a browser.
  2. Then, right-click anywhere on a page and click Inspect.
  1. Next, click the >> next to Elements and select Network.
  1. Finally, refresh the page by pressing F5. If you point to an asset, StackPath should now serve the static assets from your CDN URL.
You have successfully configured StackPath for your Discourse forum!

Frequently Asked Questions

1. What is Discourse CDN

Discourse CDN means to enable CDN for your Discourse forum. Enabling CD for your Discourse forum means that your Discourse forum’s static assets are served from the CDN provider’s wide network across the globe.

The implication is that your forum loads faster for your visitors.

2. How do I create a Domain CDN?

To create a domain CDN, add the CDN URL when you configure CDN on your provider’s site. When you do this, your provider will display the A and CNAME records you need to add to your DNS provider.

Next, open your account on your DNS provider’s website and create the A and CNAME records. The A DNS record will point your original domain URL to your CDN provider’s provided IP address.

On the other hand, the CNAME record will point your CDN domain to the CDN URL your CDN provided assigned to your domain when you signed up.

3. Is Discord and Discourse the same?

No, Discord is different from Discourse. While the two names may sound similar, they are not the same!

Discord is a video game chat service while Discourse is forum software.

4. How do I set up a Discourse server?

There are two main steps to setting up a Discourse server. 1, create a cloud server with one of the popular providers like DigitalOcean.

Then, install Discourse, start it, and complete the setup.

5. What is a Discourse group?

When you set up a Discourse forum community, the Discourse software offers you multiple ways to control access to resources. One of such ways is by creating Discourse groups.

When you create a Discourse group, you can determine Discourse users that own the group and determine users that belong to the group.

Not only that, but you can also set permissions on the group and configure other additional settings.

Conclusion

The Discourse forum software comes with built-in support for CDN. However, as of when I configured Itechguides Community in June 2022, there was no step-by-step guide.

After some research, I decided to StackPath CDN for our Discourse. In the process, I decided to document the steps so that other people could benefit from them.

I hope that you were able to configure CDN for your Discourse forum with StackPath by following this guide. If you found the guide helpful, click on “Yes” beside the “Was this page helpful” question below.

You may also express your thoughts and opinions by using the “Leave a Comment” form at the bottom of this page.

Finally, to read more articles about WordPress and websites, visit our WordPress & Websites How-Tos page.

About the Author

Photo of author

Victor Ashiedu

Victor is the founder of InfoPress Media, publishers of Ilifeguides and Itechguides. With 20+ years of experience in IT infrastructure, his expertise spans Windows, Linux, and DevOps. Explore his contributions on Itechguides.com for insightful how-to guides and product reviews.

Related Articles

Get in Touch

We're committed to writing accurate content that informs and educates. To learn more, read our Content Writing Policy, Content Review Policy, Anti-plagiarism Policy, and About Us.

However, if this content does not meet your expectations, kindly reach out to us through one of the following means:

  1. Respond to "Was this page helpful?" above
  2. Leave a comment with the "Leave a Comment" form below
  3. Email us at [email protected] or via the Contact Us page.

Leave a comment