# Problem in installing Let's Encrypt SSL for www and non-www

**URL:** https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515
**Category:** Self-hosting
**Created:** [5월 26, 2018, 6:37오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515 "2018-05-26T18:37:22Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Gulshan\_Kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gulshan_kumar/32/119562_2.png) [@Gulshan\_Kumar](https://meta.discourse.org/u/Gulshan_Kumar)
#### Post date: [5월 26, 2018, 6:37오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/1 "2018-05-26T18:37:22Z")

</div>

TLDR: Only one version is working with SSL, either www or non-www, as same as hostname provided while installation.

It’s related to Let’s Encrypt SSL installation as written [at Docs](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md).

So, after launching setup it was asked to enter

```plaintext
Hostname for your Discourse? [discourse.example.com]: 

```

So, I typed `example.app`

Next, after installing Discourse, I am facing one problem that SSL is not working for the www version.  
For non-www, it’s works fine.

Ideally, I would like to have SSL for www and non-www version also.

* * *

I repeated entire process this time with `www.example.com` hostname, then SSL for non-www is not working.

What’s I am missing?

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [5월 26, 2018, 6:55오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/2 "2018-05-26T18:55:30Z")

</div>

An easy solution without much messing with the core will be to run discourse behind an nginx reverse proxy and configuring ssl from there.

Other way (I’m not very sure of it) may be to add a letsencrypt command to the ‘after commands’ in app.yml.

---

<div class="post-metadata">

### Author: ![Gulshan\_Kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gulshan_kumar/32/119562_2.png) [@Gulshan\_Kumar](https://meta.discourse.org/u/Gulshan_Kumar)
#### Post date: [5월 26, 2018, 7:10오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/3 "2018-05-26T19:10:18Z")

</div>

My problem is similar to [SSL working on root, but not on www](https://meta.discourse.org/t/ssl-working-on-root-but-not-on-www/56647)  
I am not getting whole point. In my case, DNS record is also fine. I followed the step by step instruction, I believe it should work, but it’s not working.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [5월 26, 2018, 11:28오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/4 "2018-05-26T23:28:10Z")

</div>

Your topic & the topic you mentioned seem unrelated as discourse generates a valid certificate for the hostname you specify during install, in the other topic, when they install on www, their cert reports as invalid. I don’t think discourse supports multiple domains for standalone install natively.

---

<div class="post-metadata">

### Author: ![PoojaPatel](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@PoojaPatel](https://meta.discourse.org/u/PoojaPatel)
#### Post date: [7월 7, 2018, 7:31오전 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/5 "2018-07-07T07:31:05Z")

</div>

Is there any solution for above problem?

Currently i have installed discourse on “[example.com](http://example.com)”. I have installed lets encrypt on [example.com](http://example.com) but did not work with www version.

I want to run discourse site as [https://www.example.com](https://www.example.com)

How can i do that?

---

<div class="post-metadata">

### Author: ![Gulshan\_Kumar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gulshan_kumar/32/119562_2.png) [@Gulshan\_Kumar](https://meta.discourse.org/u/Gulshan_Kumar)
#### Post date: [7월 7, 2018, 8:25오전 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/6 "2018-07-07T08:25:28Z")

</div>

@PoojaPatel  
Assuming, www is your canonical version for Discourse. But you installed Let’s Encrypt only for apex domain.

Here’s fix…

- Re-install Discourse
- Install SSL for your _www_ because that is your canonical
- Restore Discourse backup
- Setup Cloudflare
- Go to DNS
- Enable its DNS only for www CNAME or A record.
- However must enable its DNS as well proxy for apex domain
- Choose Flexible SSL
- Force HTTPS

EXPECTED: HTTPS version should work fine for redirecting users from non-www to www version. Once I fixed SSL error this problem using this method.

Short version without re-installing SSL at www as per your canonical URL, That I cannot recommend.  
(Setup Cloudflare proxy completely over www and non-www)

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [7월 7, 2018, 9:11오전 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/7 "2018-07-07T09:11:59Z")

</div>

An easier solution is to run discourse behind a reverse proxy like nginx and setting up the SSL and appropriate redirects from there as enabling cloudflare for discourse brings in a whole lot of problems on it’s own.

---

<div class="post-metadata">

### Author: ![PoojaPatel](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@PoojaPatel](https://meta.discourse.org/u/PoojaPatel)
#### Post date: [7월 7, 2018, 3:42오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/8 "2018-07-07T15:42:10Z")

</div>

When I re-install discourse, is my website hostname as [www.example.com](http://www.example.com)?

I have installed discourse One-Click Application from DO. Which method are you recommend, One click or Linux command?

> Install SSL for your _www_ because that is your canonical

When i installing SSL from below method, I have not entered my domain details, so where i have to add www version of my website address?

> [@Set up HTTPS support with Let's Encrypt](https://meta.discourse.org/t/setting-up-lets-encrypt/40709):
>
> bookmark This is a guide for enabling HTTPS on an existing Discourse installation using Let’s Encrypt. It assumes prior installation without HTTPS enabled. person_raising_hand Required user level: System Administrator exclamation This guide is only for existing installs where HTTPS is not enabled. Following the [official setup guide](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md) automatically enables HTTPS by default. So you’d like to add https to your Discourse absolutely free, courtesy of our friends at [Let’s Encrypt?](https://letsencrypt.org/)bell I…

> However must enable its DNS as well proxy for apex domain

Pls, can you let me more, how to do above step?

> Force HTTPS - which option i have to select because there are three option related to https?

1. Always use HTTPS
2. HTTP Strict Transport Security (HSTS)
3. Automatic HTTPS Rewrites

---

<div class="post-metadata">

### Author: ![brahn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brahn/32/109267_2.png) [@brahn](https://meta.discourse.org/u/brahn)
#### Post date: [7월 8, 2018, 5:37오전 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/9 "2018-07-08T05:37:01Z")

</div>

> [@Gulshan\_Kumar](#):
>
> Ideally, I would like to have SSL for www and non-www version also.

This is how the Let’s encrypt template requests the certificate:

> <https://github.com/discourse/discourse_docker/blob/master/templates/web.letsencrypt.ssl.template.yml#L59>

Specifically `--issue -d $$ENV_DISCOURSE_HOSTNAME` meaning that it only issues a request for the hostname given to discourse. In order to get both www and non-www you need to adjust the template to issue more than one `-d` argument.

Something like as shown here:  
(read the replies, some adjustments to the original topic are necessary but I am unable to edit it)

> [@Set up Let’s Encrypt with multiple domains / redirects](https://meta.discourse.org/t/setting-up-let-s-encrypt-with-multiple-domains/56685):
>
> NOTE: @pfaffman says: This page needs to be cleaned up. There is now a new ENV setting that will let you add more hostnames. In your app.yml under your DISCOURSE\_HOSTNAME line (it can go many places but that one makes sense), add DISCOURSE\_HOSTNAME\_ALIASES: domain.com,other.domain.com and early reports suggest that you’ll get valid certs for those domains and that accessing https://domain.com will properly redirect you to your DISCOURSE\_HOSTNAME without a certificate error. If you do that an…

---

<div class="post-metadata">

### Author: ![tomtjes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tomtjes/32/131271_2.png) [@tomtjes](https://meta.discourse.org/u/tomtjes)
#### Post date: [5월 25, 2019, 8:24오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/10 "2019-05-25T20:24:39Z")

</div>

Similar situation here. I installed Discourse on `example.com` and had a CNAME DNS record for `www.example.com`.

Now I went to [https://check-your-website.server-daten.de](https://check-your-website.server-daten.de) and got a bad rating, because the SSL certificate was not valid for `www.example.com` and also `http://www.example.com` was forwarding to `https://example.com`.

Steps I took:

- Replace CNAME record for `www.example.com` by A and AAAA records.
- Add `www.example.com` as an additional domain to app.yml following  
[(Superseded) Redirect additional domain(s) to your Discourse instance](https://meta.discourse.org/t/redirect-single-multiple-domain-s-to-your-discourse-instance/18492)

```plaintext
  after_web_config:
  - replace:
      filename: /etc/nginx/nginx.conf
      from: /sendfile.+on;/
      to: |
        server_names_hash_bucket_size 64;
        sendfile on;
  - file:
      path: /etc/nginx/conf.d/discourse_redirect_1.conf
      contents: |
        server {
          listen 80;
          server_name www.example.com;
          return 301 $scheme://example.com$request_uri;
        }

```

- Adjust SSL following [Set up Let’s Encrypt with multiple domains / redirects](https://meta.discourse.org/t/setting-up-let-s-encrypt-with-multiple-domains/56685)

```plaintext
after_ssl:
  - replace:
      filename: "/etc/runit/1.d/letsencrypt"
      from: /-k 4096 -w \/var\/www\/discourse\/public/
      to: |
        -d www.example.com -d example.com -k 4096 -w /var/www/discourse/public

  - replace:
      filename: "/etc/runit/1.d/letsencrypt"
      from: /-k 4096 --force -w \/var\/www\/discourse\/public/
      to: |
        -d www.example.com -d example.com -k 4096 --force -w /var/www/discourse/public
  - replace:
      filename: "/etc/nginx/conf.d/discourse.conf"
      from: /return 301 https.+/
      to: |
        return 301 https://$host$request_uri;
  - replace:
      filename: "/etc/nginx/conf.d/discourse.conf"
      from: /gzip on;[^\}]+\}/m
      to: |
        gzip on;
        add_header Strict-Transport-Security 'max-age=31536000';

```

- `./launcher rebuild app`

Now, the rating for the site has improved, but one issue remains:

> Wrong redirect http ⇒ http

Somewhere there’s 301 redirect  
`http://www.example.com ⇒ http://example.com`.  
I guess it should be  
`http://www.example.com ⇒ https://www.example.com ⇒ https://example.com`

Any idea how to achieve this?

---

<div class="post-metadata">

### Author: ![Brandon\_Martus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brandon_martus/32/127631_2.png) [@Brandon\_Martus](https://meta.discourse.org/u/Brandon_Martus)
#### Post date: [12월 3, 2019, 7:00오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/11 "2019-12-03T19:00:08Z")

</div>

참고로, 이 게시글을 참조하시는 분들을 위해 말씀드리자면, `/etc/runit/1.d/letsencrypt` 파일이 한 달여 전부터 약간 변경되었습니다. 이로 인해 www 및 non-www에 대한 _replace_ 정규식이 더 이상 작동하지 않습니다.

업데이트된 정보는 다음 게시글을 참조해 주세요: [Set up Let’s Encrypt with multiple domains / redirects](https://meta.discourse.org/t/setting-up-let-s-encrypt-with-multiple-domains/56685)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [9월 8, 2023, 3:03오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/12 "2023-09-08T15:03:02Z")

</div>



---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [9월 8, 2023, 3:14오후 UTC](https://meta.discourse.org/t/problem-in-installing-lets-encrypt-ssl-for-www-and-non-www/88515/13 "2023-09-08T15:14:09Z")

</div>


