# 让“www”在 Discourse 中正常工作

**URL:** <https://meta.discourse.org/t/making-www-work-with-discourse/150785>\
**Category:** Support\
**Created:** [2020年五月8日 04:23 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785 "2020-05-08T04:23:38Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![syl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syl/32/98883_2.png) [@syl](https://meta.discourse.org/u/syl)\
**Post date:** [2020年五月14日 16:44 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/21 "2020-05-14T16:44:01Z")

</div>

不，无需额外安装。

此外，我唯一需要添加的代码块是：

```plaintext
  after_ssl:
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d mywebsite.org --keylength"

```

（HTTP 到 HTTPS 的重定向似乎在没有另外两个带有 `nginx` 的 `replace` 块的情况下也能正常工作。）

---

<div class="post-metadata">

**Author:** ![Milo](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Milo](https://meta.discourse.org/u/Milo)\
**Post date:** [2020年五月15日 13:11 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/22 "2020-05-15T13:11:00Z")

</div>

所以我终于有时间来完成“使用多个域名设置 Let’s Encrypt

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2020年五月15日 13:15 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/23 "2020-05-15T13:15:50Z")

</div>

> [@Milo](#):
>
> 什么是页面规则？

> **[Cloudflare Rules](https://developers.cloudflare.com/rules/)**
>
> Use Cloudflare Rules to adjust requests and responses, configure settings, and trigger actions for specific requests.

免费实施，即使 Cloudflare 不是您的注册商。支持 HTTPS，在您的 Discourse 安装中无需额外复杂性。

---

<div class="post-metadata">

**Author:** ![Milo](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Milo](https://meta.discourse.org/u/Milo)\
**Post date:** [2020年五月15日 13:19 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/24 "2020-05-15T13:19:51Z")

</div>

谢谢，我目前尚未使用 Cloudflare，因此之前未曾接触过这些。我选择了另一条路径，并参考了上述指南，基本解决了我的问题。你发帖的时候，我刚好提交了上面的 [回复](https://meta.discourse.org/t/making-www-work-with-discourse/150785/22?u=milo)。

---

<div class="post-metadata">

**Author:** ![syl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syl/32/98883_2.png) [@syl](https://meta.discourse.org/u/syl)\
**Post date:** [2020年五月15日 13:31 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/25 "2020-05-15T13:31:59Z")

</div>

> [@Milo](#):
>
> 我在我的 containers/app.yml 文件中添加的内容比你多得多

请查看 [这个网站](http://www.castafiore.org)；它是否包含你所需的所有重定向？它仅通过一个 `replace` 块（见上文）和此 DNS 设置完成（我仅对电子邮件 TXT 记录进行了脱敏处理）：

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/a/aa493bdf2dcffce452f413840d8a6721b4ec2f66.png)

我在控制台中没有收到任何警告。

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2020年五月15日 14:02 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/26 "2020-05-15T14:02:44Z")

</div>

是的，只需准备好当 Let’s Encrypt 配置变更时可能会出问题。

当 Let’s Encrypt 更新以支持椭圆曲线时，你上面依赖的方法曾中断了几周。

---

<div class="post-metadata">

**Author:** ![Milo](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Milo](https://meta.discourse.org/u/Milo)\
**Post date:** [2020年五月15日 15:30 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/28 "2020-05-15T15:30:43Z")

</div>

唯一的区别是我在 DNS 中没有 CAA 记录。我会使用您使用的相同值添加它。

我假设您的 Discourse 主机名是 [www.example.com](http://www.example.com)，您确定访问 [https://example.com](https://example.com) 时不会收到警告吗？

在 Android 上的 Chrome 中，这个警告更为严重，它会完全阻止访问该网站，并且不会进行重定向。

---

<div class="post-metadata">

**Author:** ![Milo](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Milo](https://meta.discourse.org/u/Milo)\
**Post date:** [2020年五月15日 15:33 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/29 "2020-05-15T15:33:02Z")

</div>

你把我搞糊涂了 🙂 我需要留意什么，或者要准备好修复什么？

---

<div class="post-metadata">

**Author:** ![syl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syl/32/98883_2.png) [@syl](https://meta.discourse.org/u/syl)\
**Post date:** [2020年五月15日 15:47 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/30 "2020-05-15T15:47:17Z")

</div>

> [@Milo](#):
>
> 我假设你的 Discourse 主机名是 [www.example.com](http://www.example.com)

正确。

> [@Milo](#):
>
> 你确定访问 [https://example.com](https://example.com) 时不会收到警告吗？

是的，我确定，控制台里没有警告。

---

<div class="post-metadata">

**Author:** ![Milo](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@Milo](https://meta.discourse.org/u/Milo)\
**Post date:** [2020年五月15日 18:45 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/31 "2020-05-15T18:45:43Z")

</div>

我想我找到问题了，我之前是这样写的：

```
after_ssl:
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d example.com -d www.example.com --keylength"

```

而正确的写法应该是：

```
after_ssl:
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d example.com --keylength"

```

注意最后一行，我之前包含了 [example.com](http://example.com) 和 [www.example.com](http://www.example.com)。

我还把 `return 301 https://$host$request_uri;` 改成了 `return 301 $scheme://$host$request_uri;`，重新构建后看起来已经可以正常工作了。

现在我唯一担心的是 @Stephen 提到的，如果 letsencrypt 的配置发生变化，可能会导致问题。

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2020年五月15日 23:08 UTC](https://meta.discourse.org/t/making-www-work-with-discourse/150785/32 "2020-05-15T23:08:43Z")

</div>

去年9月9日的一次变更打破了您正在遵循的方法，由于该实现超出了标准安装范围，因此直到10月31日才发布解决方案。如果您查看您遵循的主题以及维基上的编辑历史，可以清楚地看到相关记录。

由于您并不需要深入进行额外的配置，因此我建议不要这样做。另一方面，当 Let’s Encrypt 确实发生变更且您受到影响时，我们可以将您引回此主题。

[上一頁](https://meta.discourse.org/t/making-www-work-with-discourse/150785.md?page=1)
