# 与 Apache 一起运行 Discourse docker

**URL:** https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625
**Category:** Self-hosting
**Created:** [2020年八月21日 07:17 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625 "2020-08-21T07:17:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rebelCoder](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rebelcoder/32/191230_2.png) [@rebelCoder](https://meta.discourse.org/u/rebelCoder)
#### Post date: [2020年八月21日 07:17 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/1 "2020-08-21T07:17:18Z")

</div>

你好。

我试图在现有服务器上设置 Discourse Docker。目前我没有运行其他 Docker 容器。

我的服务器运行着 Apache（WordPress 网站）以及一些其他 Web 服务。

我无法弄清楚如何将子域名 ‘forum.rebelscience.club’ 路由到我的 Docker 容器。

当系统提示我：

```plaintext
您的 Discourse 主机名？[discourse.example.com]: forum.rebelscience.club

```

我看到的提示是：

```plaintext
正在检查您的域名...
警告：计算机的 443 端口似乎无法通过主机名访问：forum.rebelscience.club。
警告：连接到 http://forum.rebelscience.club（端口 80）也失败。

这表明 forum.rebelscience.club 解析到了某个 IP 地址，但该地址无法到达您正在安装 Discourse 的这台机器。

第一步是确认 forum.rebelscience.club 是否解析到了本服务器的 IP 地址。
您通常可以在购买域名的同一位置进行此设置。

如果您确定 IP 地址解析正确，则可能是防火墙问题。
搜索“开放端口 您的云服务提供商”可能会有所帮助。

此工具仅适用于最标准的安装。如果您无法解决上述问题，则需要自行编辑 containers/app.yml，然后输入

./launcher rebuild app

```

我不确定该如何设置。端口 80 和 443 是可用的，但它们指向的是我的主域名，而不是子域名。

非常感谢您的任何建议。

---

<div class="post-metadata">

### Author: ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)
#### Post date: [2020年八月21日 07:20 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/2 "2020-08-21T07:20:28Z")

</div>

> [@rebelCoder](#):
>
> 非常感谢任何建议。

你好 @rebelCoder

这个话题在 meta 板块已经进行过广泛讨论；你可以在 meta 中搜索“apache 反向代理”，找到许多全面且非常详细的主题帖。

简而言之，你需要将 Apache 服务器的虚拟主机配置为 Discourse 的反向代理。

关于此设置的 Apache2 具体配置，已在 meta 上多次发布。

希望这能帮到你。

 ![Screen Shot 2020-08-21 at 2.22.48 PM](https://global.discourse-cdn.com/meta/original/3X/f/f/ff74c54613750fcc7ec4f101f75ffa9d227fe86e.jpeg)

---

<div class="post-metadata">

### Author: ![rebelCoder](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rebelcoder/32/191230_2.png) [@rebelCoder](https://meta.discourse.org/u/rebelCoder)
#### Post date: [2020年八月21日 07:55 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/3 "2020-08-21T07:55:35Z")

</div>

抱歉，我本应提到我已经查看并尝试了该论坛和 Digital Ocean 上的一些解决方案，但仍然无法使其正常工作。我从未设置过 Docker。

让我分享一下我当前的配置：

```plaintext
/ets/hosts:
127.0.0.1 forum.rebelscience.club

```

主机文件和 DNS 记录均正常工作，因为今天我在此处运行了 phpBB。现在，我尝试将其指向一个运行 Discourse 的 Docker 容器。

在 **`containers/app.yml`** 中

我更新了端口：

```plaintext
expose:
  - "8081:80" # http
  - "8443:443" # https

```

在 **`/etc/apache2/sites-enabled/discourse.conf`** 中

```plaintext
<VirtualHost *:80>
  ServerName forum.rebelscience.club
  ServerAlias www.forum.rebelscience.club

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
  </IfModule>
</VirtualHost>

```

我还漏掉了什么？运行 `./discourse-setup` 仍然失败，错误信息与原帖中相同。

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [2020年八月21日 08:08 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/4 "2020-08-21T08:08:14Z")

</div>

我认为你应该为 443 端口配置一个虚拟主机。话说回来，80 端口的错误有些奇怪，也许你的 DNS 中缺少某些配置（比如一个 CNAME 记录）？

---

<div class="post-metadata">

### Author: ![rebelCoder](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rebelcoder/32/191230_2.png) [@rebelCoder](https://meta.discourse.org/u/rebelCoder)
#### Post date: [2020年八月21日 08:19 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/5 "2020-08-21T08:19:42Z")

</div>

这有点奇怪。看起来设置过程有点过于繁琐。

我只有 `forum.rebelscience.club` 的 `A 记录`。

我已经更新了包含证书的 .conf 文件：

**cat /etc/apache2/sites-enabled/discourse.conf**

```plaintext
<VirtualHost *:80>
  ServerName forum.rebelscience.club
  ServerAlias www.forum.rebelscience.club

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
  </IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.forum.rebelscience.club [OR]
RewriteCond %{SERVER_NAME} =forum.rebelscience.club
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

```

**cat /etc/apache2/sites-enabled/discourse-le-ssl.conf**

```plaintext
<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName forum.rebelscience.club
  ServerAlias www.forum.rebelscience.club

  <IfModule proxy_module>
    ProxyPreserveHost on
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
  </IfModule>

SSLCertificateFile /etc/letsencrypt/live/forum.rebelscience.club/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/forum.rebelscience.club/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

```

现在我看到 **`503 Service Unavailable`** 错误。

我完全不知所措了，还需要做什么？setup.sh 仍然用原始消息失败。

---

<div class="post-metadata">

### Author: ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)
#### Post date: [2020年八月21日 09:00 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/6 "2020-08-21T09:00:52Z")

</div>

> [@rebelCoder](#):
>
> `8081`

在上面的示例配置中，您应该仅在 Docker 中暴露端口 8081（而不是端口 80 或端口 443）。

端口 80 和 443 由容器外部的反向代理暴露，该流量会被代理到端口 8081（即您上面的示例中），也就是您在容器内部暴露并映射到内部端口 80 的端口。

这只有在您已将容器内部的端口 80 映射到主机暴露的端口 8081 时才能正常工作。

```plaintext
expose:
  - "8081:80" # http

```

希望这能帮到您。

附：@rebelCoder，您 SSL 方面的 apache2 配置缺少许多必要的配置信息。

请参阅此帖子：

> [@I want to install using a reverse proxy for Apache](https://meta.discourse.org/t/i-want-to-install-using-a-reverse-proxy-for-apache/158519/5):
>
> Dear @Teraterayuki … Here is an example set of working Apache2 virtual hosts for a reverse proxy to a unix domain socket in a Discourse container: Port 80 \<VirtualHost \*:80\> ServerName mysite.mydomain.com ServerAdmin webmaster@localhost ProxyPreserveHost On #ProxyPass / http://127.0.0.1:8888/ #ProxyPassReverse / http://127.0.0.1:8888/ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg.…

---

<div class="post-metadata">

### Author: ![rebelCoder](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rebelcoder/32/191230_2.png) [@rebelCoder](https://meta.discourse.org/u/rebelCoder)
#### Post date: [2020年八月21日 09:30 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/7 "2020-08-21T09:30:56Z")

</div>

这已不再是问题，可以关闭。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2020年八月21日 13:20 UTC](https://meta.discourse.org/t/running-discourse-docker-alongside-apache/161625/8 "2020-08-21T13:20:15Z")

</div>

> [@rebelCoder](#):
>
> 运行 `./discourse-setup` 仍然失败，并显示原始帖子中的错误信息。

您不能使用 `discourse-setup`。您必须按照关于在 Apache 上运行的主题中的说明，手动编辑 app.yml 文件。
