为您的 Discourse Docker 设置启用 SSL / HTTPS

本指南可能已过时,因为现在几乎没有理由不使用内置的 Let’s Encrypt 证书,因为它“即开即用”。另请参阅:

2023-04-10 @pfaffman 说:此内容主要保留以供参考。

所以,您想为基于 Docker 的 Discourse 设置启用 SSL?我们开始吧!

本指南假设您使用了所有标准的安装默认设置——配置文件位于 /var/discourse/containers/app.yml,Discourse docker 安装在:/var/discourse

购买 SSL 证书

前往 namecheap 或其他 SSL 证书提供商,为您的域名购买 SSL 证书。遵循他们记录的所有步骤来生成私钥和 CSR,最后获得您的证书。我使用了 Apache 默认设置,它们可以正常工作。

将您的私钥和证书保存在安全的地方。

放置证书和密钥

获取签名证书和密钥,并将它们放入 /var/discourse/shared/standalone/ssl/ 文件夹

私钥是:

/var/discourse/shared/standalone/ssl/ssl.key

证书是

/var/discourse/shared/standalone/ssl/ssl.crt

文件名至关重要,不要偏离它们,否则您的 nginx 模板将不知道在哪里找到证书。

查看您的 app.yml 配置文件,了解共享文件夹的挂载位置。

    volumes:
      - volume:
          host: /var/discourse/shared/standalone
          guest: /shared

本质上,文件必须位于容器内的 /shared/ssl/ssl.key/shared/ssl/ssl.crt

为了让所有客户端都能从您的证书找到到受信任的根证书的路径(即不向用户显示任何警告),您可能需要像这样连接提供商的证书文件:

cat "Your PositiveSSL Certificate" "Intermediate CA Certificate" "Intermediate CA Certificate" >> ssl.crt

配置 NGINX

从您的 app.yml 配置文件中添加对 nginx ssl 模板的引用:

    templates:
      - "templates/postgres.template.yml"
      - "templates/redis.template.yml"
      - "templates/web.template.yml"
      - "templates/web.ratelimited.template.yml"
      - "templates/web.ssl.template.yml"

配置您的 Docker 容器

告诉您的容器监听 SSL

    expose:
      - "80:80"
      - "443:443"

引导您的 Docker 容器

重建您的应用程序

./launcher rebuild app

享受成果,您完成了!

故障排除

如果出现任何问题,请务必使用以下命令查看日志:

./launcher logs app

工作原理

该模板使用 nginx 配置 TLSv1.2 和 TLSv1.3、强加密套件、HSTS 标头和会话票据设置。它使用 nginx 配置出口(outlets)来注入 SSL 配置。

该镜像具有重写规则,会将端口 80 上的任何请求重定向到 https://DISCOURSE_HOST_NAME,并且还会将端口 443 上对其他主机名的请求重定向到规范主机名。

自定义此设置非常简单,请参阅:

您可以复制该文件并根据需要修改模板。

使用模板和出口的优势在于,我们可以保留 Discourse 推荐的所有其他 NGINX 设置,因为这些设置会随时间变化。

测试您的配置

请参阅 SSL Server Test (Powered by Qualys SSL Labs) 以确保一切正常。某些浏览器和操作系统组合可能可以接受部分配置的 https,所以请先在此处检查。

75 个赞
I need help with SSL
Broken image since https
Troubles installing SSL
NGINX Proxy Mixed Content Error
SSL on Discourse / DO sub-domain of Heroku hosted domain
Force Discourse to use SSL/HTTPS through CloudFlare
How to force redirect from https to http on Docker installation
SSL Let's Encrypt Error After Installation
Cannot connect to IP address and no errors in log
Can i change Lets Encrypt to EssentialSSL / Wildcard SLL
I have a very difficult problem installing ssl - please help
Go Daddy SSL certificate installation error in D.O. server
How Do I Uninstall SSL Certificate?
How to Set Up SSL in Discourse
Site down after enabling SSL
SSL installation
SSL certificate expired and after that - Error 404 Not Found
Skipping built-in SSL certificate?
Unable to renew Let's encrypt certificate
Adding SSL certificate
Getting Cloudflare 521 Error After Upgrade to 3.5.0.beta8-dev
Let's encrypt failing for IP behind firewall
Unable To Connect/Connection Refused due to https certificates
Rebuild goes into a loop
Transfer from bitnami to normal discourse
My site is down with a weird SSL notification
Https with let's encrypt behind a vpn?
Cannot install custom SSL new_file: no such file
Favicon is failing to load for logged-in users
How to install SSL certificate in Discourse
Disabe letsencrypt failed and Run discourse-setup had some not normal alert
How to modify Dockerfile?
DNS validation for Let's Encrypt?
How might we better structure #howto?
Hit Let's encrypt renewal limit
Unable To Connect/Connection Refused due to https certificates
Setting up Discourse with SSL on Docker with AWS ELB breaks and returns 503 Service Unavailable (Back-end server is at capacity)
Disabe letsencrypt failed and Run discourse-setup had some not normal alert
Global setting to hide origin IP from everywhere - is it possible?
Latest update requires cache purge in CloudFlare