# Force Discourse to use SSL/HTTPS through CloudFlare

**URL:** https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212
**Category:** Sysadmins
**Tags:** how-to, cloudflare
**Created:** [August 25, 2016, 7:24pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212 "2016-08-25T19:24:46Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kuyashi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuyashi/32/82068_2.png) [@kuyashi](https://meta.discourse.org/u/kuyashi)
#### Post date: [August 25, 2016, 7:24pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/1 "2016-08-25T19:24:46Z")

</div>

How to use CloudFlare’s platform to force all traffic over HTTPS connection using page rules.  
This is an up to date and user-friendly (fool-proof) way that I use each time and it works perfectly.

**Sign up to CloudFlare** [here](https://cloudflare.com) - they offer SSL/HTTPS on their Free plan, so that will be just fine for us.

**Add your site** [here](https://www.cloudflare.com/a/add-site) - the system will scan for DNS records, make sure all are correct and add any records not picked automatically by the scan i.e. MX records.

**You will the have to add the CloudFlare nameservers to your domain.** This can be done with whoever your purchased your domain with on their control panel - differs for each provider - some examples:  
-GoDaddy: [here.](https://ie.godaddy.com/help/set-custom-nameservers-for-domains-registered-with-godaddy-12317)  
-Namecheap: [here.](https://www.namecheap.com/support/knowledgebase/article.aspx/767/10/how-can-i-change-the-nameservers-for-my-domain)  
-Bluehost: [here.](https://my.bluehost.com/cgi/help/222)

**Once your nameservers have been successfully edited** (you can check this by opening a terminal and issuing the command:  
`whois yourdomain.com`) towards the bottom of the output you should see CloudFlare’s nameservers:

` Name Server: LARA.NS.CLOUDFLARE.COM`  
`Name Server: GABE.NS.CLOUDFLARE.COM`

**Now we can head back to our CloudFlare control panel for your new site:**

 ![](https://global.discourse-cdn.com/meta/original/3X/1/2/12dbe49abfa9ca461adc3d1258512bae319b3d97.png)

Click on the page rules section from the icon menu. Click on create page rule and fill in as follows:

 ![](https://global.discourse-cdn.com/meta/original/3X/2/4/244612388301ee27df396a5a2644f97b0ed18b4a.png)

Enter your domain i the format as in image above: `http://*yourdomain.com/*` this will force all sub-domains (the \* before the domain) and sub-directories (the \* after the domain) to use HTTPS.

Click on “add setting” and choose “Always use HTTPS” from the drop down menu. For “Order” yo can leave as “First”.

Click on “Save and Deploy”.

The setting may take up to 15 minutes to take effect, but then all your traffic should re-direct to [https://yourdomain.com](https://yourdomain.com) .

**NOTE:**  
In order to maintain full HTTPS (green padlock) you will need to go to Discourse settings (/admin/site\_settings/category/required) and search for all settings containing `http://..../....` and change the links to `https://.../....` .

You can check SSL status at: [SSL Server Test (Powered by Qualys SSL Labs)](https://www.ssllabs.com/ssltest/) :

 ![](https://global.discourse-cdn.com/meta/original/3X/7/3/73a1590a438a338f13eda3205645dbab41dc584d.png)

**NOTE:**  
As noted by @mpalmer below:

> … In order for the connection between Cloudflare and your origin to be similarly secure as the connection between the browser and Cloudflare, you need to setup SSL on the origin server, too.

For setting up SSL on your server:

> [@Allow SSL / HTTPS for your Discourse Docker setup](https://meta.discourse.org/t/allowing-ssl-https-for-your-discourse-docker-setup/13847):
>
> This guide is likely out of date as there are now very few reasons not to use the built-in Let’s Encrypt certificate that Just Works. See also: 2023-04-10 @pfaffman says: This is left here mostly for historical purposes. So you’d like to enable SSL for your Docker-based Discourse setup? Let’s do it! This guide assumes you used all the [standard install](https://meta.discourse.org/t/142537?silent=true) defaults – a container configuration file at/var/discourse/containers/app.yml and Discourse docker is installed at: /var/discourse Buy a SS…

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [August 25, 2016, 10:39pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/2 "2016-08-25T22:39:12Z")

</div>

You appear to be missing the steps where you setup TLS between Cloudflare and your origin. That somewhat defeats the purpose of using HTTPS in the first place, and in fact provides a false sense of security for site visitors.

---

<div class="post-metadata">

### Author: ![kuyashi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuyashi/32/82068_2.png) [@kuyashi](https://meta.discourse.org/u/kuyashi)
#### Post date: [August 25, 2016, 10:42pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/3 "2016-08-25T22:42:00Z")

</div>

I was under the impression that enabling/enforcing from the cloudflare side would suffice.  
Could you elaborate ?

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [August 25, 2016, 10:55pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/4 "2016-08-25T22:55:16Z")

</div>

When you put a proxy such as Cloudflare into the connection path, said proxy needs to be able to decrypt the HTTPS traffic into plain HTTP so that the proxy can do its business (sending cached responses, filtering out shenanigans, etc). This means that the HTTPS connection is actually terminating on Cloudflare’s servers, and then another connection is being made to your server (the origin). In order for the connection between Cloudflare and your origin to be similarly secure as the connection between the browser and Cloudflare, you need to setup SSL on the origin server, too.

Personally, I find the fact that Cloudflare allows this misleading setup to be deeply disappointing. They’re making the claim, “yes, your activities can’t be trivially monitored” (to those few users who look for the padlock, anyway), but in actual fact everyone between Cloudflare and your origin can see everything. Worse, because Cloudflare’s DCs are a choke point for a _lot_ of traffic, sitting just outside Cloudflare’s DCs and capturing everything is probably going to get you a lot more interesting stuff than sniffing any but the largest transcontinental links.

---

<div class="post-metadata">

### Author: ![kuyashi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuyashi/32/82068_2.png) [@kuyashi](https://meta.discourse.org/u/kuyashi)
#### Post date: [August 25, 2016, 10:57pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/5 "2016-08-25T22:57:55Z")

</div>

Thanks that @mpalmer i’ll be sure to edit OP to reflect.

---

<div class="post-metadata">

### Author: ![Abdulwahab\_Suleiman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abdulwahab_suleiman/32/75605_2.png) [@Abdulwahab\_Suleiman](https://meta.discourse.org/u/Abdulwahab_Suleiman)
#### Post date: [July 21, 2017, 7:45pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/6 "2017-07-21T19:45:05Z")

</div>

Hi, thanks very much for this article.

I came across your post last week and implemented the above steps on my blog but after two days of applying my flexible SSL certificate was still pending. I contacted their support and they explained the delay wasn’t from their own end.

I later came across another article on Let’s Encrypt free SSL. I implemented the steps and it was like magic.

Check my blog [https://www.wiki212.com/](https://www.wiki212.com/)

The let’s encrypt SSL is active though will have to renew it every 3months.

Thanks again for the great piece.

---

<div class="post-metadata">

### Author: ![Nelson](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@Nelson](https://meta.discourse.org/u/Nelson)
#### Post date: [July 21, 2017, 8:10pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/7 "2017-07-21T20:10:18Z")

</div>

The page rule is no longer necessary. You can switch on both forcing of https and rewriting http to https requests with a toggle 🕶

Both can be found on the crypto settings page.

![](https://global.discourse-cdn.com/meta/original/3X/1/4/146e9d03ccaf4ce34da405fc8a616d72b19039a3.jpeg)

And:

![](https://global.discourse-cdn.com/meta/original/3X/2/7/27189c7f154036d96fff90ab8e6ad48756e6eee9.jpeg)

---

<div class="post-metadata">

### Author: ![kuyashi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuyashi/32/82068_2.png) [@kuyashi](https://meta.discourse.org/u/kuyashi)
#### Post date: [July 21, 2017, 8:15pm UTC](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212/8 "2017-07-21T20:15:05Z")

</div>

Cool, glad it helped and yes Let’s Encrypt SSL’s are a great convenience.
