# \[DigitalOcean\] A 记录中包含“www”的主机名显示空白页面

**URL:** https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227
**Category:** Self-hosting
**Tags:** hosting
**Created:** [2019年九月11日 03:45 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227 "2019-09-11T03:45:59Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月11日 03:45 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/1 "2019-09-11T03:45:59Z")

</div>

各位成员，

在我的 DigitalOcean Droplet 的 DNS 记录中，我为域名创建了两条 **"A"** 记录：一条主机名为 **"www"** (`www.HardwareMana.community`)，另一条为 **空白** (`HardwareMana.community`)，它们都指向 DigitalOcean 的云服务器。目前这两条 **"A"** 记录具有相同的 IP 地址，但只有空白记录能正常加载，而主机名为 **"www"** 的记录显示为空白页面。

请提供正确的 DNS 设置建议，谢谢！

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [2019年九月11日 04:33 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/2 "2019-09-11T04:33:59Z")

</div>

请尝试以下操作：

| 类型 | 主机名 | 值 |
| --- | --- | --- |
| A | hardwaremana.community | 157.245.106.210 |
| CNAME | www.hardwaremana.community | hardwaremana.community. |
| CNAME | \*hardwaremana.community | hardwaremana.community. |

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月11日 04:54 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/3 "2019-09-11T04:54:45Z")

</div>

![DNS%20settinsg%202](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/optimized/3X/7/7/77d6ab6f1cdf4a5cfec87d3ce09e9150be6e5985_2_689x51.jpeg)

 ![DNS%20settings%201](https://global.discourse-cdn.com/meta/original/3X/6/a/6ad95c4f923cee7085b7880dc4b6c90d3c92a767.jpeg)  
已完成，但 [www.HardwareMana.community](http://www.HardwareMana.community) 仍显示为 **空白** 页面。  
DigitalOcean 上的 DNS 记录未在值中注册\*\*（点）\*\*。  
我是否还需要在域名注册商处进行任何设置？

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月15日 17:34 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/4 "2019-09-15T17:34:42Z")

</div>

还有一点，我发现我在 DigitalOcean 云服务器上安装的 Discourse 设置中， **Discourse 主机名** 为 `Hardwaremana.community`。这是否可能是导致我的 `www.HardwareMana.community` 域名出现问题的原因？恳请协助。  
谢谢！！

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [2019年九月15日 17:59 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/5 "2019-09-15T17:59:20Z")

</div>

不，该主机名应该是 [正确的](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md#edit-discourse-configuration)。

`您的 Discourse 主机名？[discourse.example.com]`

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2019年九月15日 18:31 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/6 "2019-09-15T18:31:52Z")

</div>

切勿在主机名中使用大写字母。

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月16日 08:19 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/7 "2019-09-16T08:19:18Z")

</div>

更正一下，我只使用 `hardwaremana.community`。请据此提供建议，谢谢 🙂

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2019年九月16日 08:22 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/8 "2019-09-16T08:22:12Z")

</div>

[![](https://img.youtube.com/vi/ocwPb8CWkZU/maxresdefault.jpg "SOLVED Domain name with WWW not working NameCheap and Kinsta") ](https://www.youtube.com/watch?v=ocwPb8CWkZU)

来看看这个。

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2019年九月16日 09:13 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/9 "2019-09-16T09:13:54Z")

</div>

您的内容安全策略仅允许通过 HTTP 加载脚本。  
您是否启用了 `force_https` 站点设置？

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月16日 09:52 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/10 "2019-09-16T09:52:55Z")

</div>

不，请进一步指导我。谢谢 @RGJ

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2019年九月16日 10:27 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/11 "2019-09-16T10:27:53Z")

</div>

```bash
ssh root@your.server.ip
cd /var/discourse
./launcher enter app
rails c
SiteSetting.force_https = true

```

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月16日 11:45 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/12 "2019-09-16T11:45:40Z")

</div>

已完成上述设置，但现在无法再连接到云服务器。因此，在将 `SiteSetting.force_https = false` 设置为 false 后，操作与之前相同。  
`https://www.hardwaremana.community` 显示无法连接。  
`www.Hardwaremana.community` 显示 **空白页面** ，但未启动 Discourse 安装。  
`hardwaremana.community` 正常启动 Discourse。

---

<div class="post-metadata">

### Author: ![xrav3nz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/xrav3nz/32/76894_2.png) [@xrav3nz](https://meta.discourse.org/u/xrav3nz)
#### Post date: [2019年九月16日 14:40 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/13 "2019-09-16T14:40:36Z")

</div>

我认为您的 DNS 配置正确。

如果您访问 `www.hardwaremana.community` 并打开控制台，**会看到关于 [内容安全策略 (CSP)](https://meta.discourse.org/t/mitigate-xss-attacks-with-content-security-policy/104243) 的错误**：

`拒绝加载脚本 'http://www.hardwaremana.community/...'，因为它违反了以下内容安全策略指令："script-src 'unsafe-eval' 'report-sample' http://hardwaremana.community/... ..."。`

请注意，只有非 `www` 主机被列入白名单，因为：

> [@Systmyz](#):
>
> **Discourse 的主机名** 为 `hardwaremana.community`

Discourse 会根据此值自动设置您的 CSP。因此，建议您选择一个（`www` 或非 `www`），并为另一个设置重定向。

---

<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: [2019年九月16日 15:08 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/14 "2019-09-16T15:08:21Z")

</div>

您无法在两个网址下发布内容。

请选择一个，并将另一个重定向。

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月17日 01:26 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/15 "2019-09-17T01:26:23Z")

</div>

感谢指出这些错误。我将使用新的值 `www.hardwaremana.community` 作为我的新 **Discourse 主机名** 重新构建 Discourse 设置。随后会进行相应的进一步重定向。

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月17日 04:13 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/16 "2019-09-17T04:13:25Z")

</div>

我已将 **Discourse 的主机名** 更改为 `www.hardwaremana.community`，现在问题变成了相反的情况。以下是我正在使用的 DNS 记录：

| 类型 | 主机名 | 值 |
| --- | --- | --- |
| A | www.hardwaremana.community | 157.245.106.210 |
| CNAME | \*.hardwaremana.community | 157.245.106.210 |

查看 Web 控制台时，发现域名 `hardwaremana.community` 存在关于 [内容安全策略 (CSP)](https://meta.discourse.org/t/mitigate-xss-attacks-with-content-security-policy/104243) 的错误。现在该如何修复这些脚本错误？恳请指导！

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2019年九月17日 04:37 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/17 "2019-09-17T04:37:51Z")

</div>

添加另一个主机名为 `hardwaremana.community` 的 A 记录  
这对我的 D/O 实例有效。

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月17日 08:41 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/18 "2019-09-17T08:41:54Z")

</div>

现在我的 DigitalOcean 云服务器 DNS 记录中已添加这些值，但 `hardwaremana.community` 仍无法启动 Discourse，并且在控制台中显示 **脚本错误** 。

| 类型 | 主机名 | 值 |
| --- | --- | --- |
| A | www.hardwaremana.community | 157.245.106.210 |
| A | hardwaremana.community | 157.245.106.210 |
| CNAME | \*.hardwaremana.community | 157.245.106.210 |

`https://www.hardwaremana.community` 显示无法连接  
`hardwaremana.community` 显示 **空白页面** 并伴有脚本错误  
`www.Hardwaremana.community` 正常启动 Discourse  
恳请提供一些解决方案。

---

<div class="post-metadata">

### Author: ![Systmyz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/systmyz/32/157841_2.png) [@Systmyz](https://meta.discourse.org/u/Systmyz)
#### Post date: [2019年九月18日 06:29 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/19 "2019-09-18T06:29:55Z")

</div>

我需要在 Discourse 配置文件（ **app.yml** ）中进行额外的域名设置吗？  
是否有专家在此，请指导或分享资源，以便我正确修改 app.yml，从而解决我的 **非 www** 域名问题。

---

<div class="post-metadata">

### Author: ![JimPas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimpas/32/148179_2.png) [@JimPas](https://meta.discourse.org/u/JimPas)
#### Post date: [2019年九月18日 07:31 UTC](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227/20 "2019-09-18T07:31:53Z")

</div>

> [@Systmyz](#):
>
> `https://www.hardwaremana.community` 显示无法连接

我刚运行了一个 SSL 查询与报告工具，结果显示您的网站没有 SSL 证书。

# SSL 查询与报告工具

SSL 检查报告会分析网站上的 SSL 证书，并提供 SSL 验证信息。该报告会检查您的域名与证书上的主机名是否不匹配，以及证书是否已过期、被吊销或不受信任。

**抱歉，出现问题。**

- 未找到证书。  
\_

甚至 Firefox 也显示所有三个域名（https、www 和非 www 版本）都不安全。  
您的域名是否有 SSL 证书？在没有 SSL 证书的情况下，进行 https 的重定向（进入或离开）很可能会返回错误。

已检查全部三个：  
https 无法建立连接；  
http (hardwaremana.community) 返回空白页面；但  
www 可以加载 Discourse（显示黑色且带斜杠的挂锁图标）。

[下一頁](https://meta.discourse.org/t/digitalocean-hostname-having-www-in-a-records-showing-blank-page/128227.md?page=2)
