Let's Encrypt を使った HTTPS サポートのセットアップ

:bookmark: これは、既存の Discourse インストールに対して Let’s Encrypt を使用して HTTPS を有効化するためのガイドです。HTTPS が無効な状態で事前にインストール済みのことを前提としています。

:person_raising_hand: 必要なユーザー権限レベル:システム管理者

:exclamation: このガイドは、HTTPS が有効化されていない既存のインストールのみを対象としています。公式セットアップガイド に従って設定を行うと、デフォルトで HTTPS が自動的に有効化されます。

Discourse に HTTPS を無料で追加したいとお考えですか?それは、Let’s Encrypt のご厚意によるものです。

:bell: サイト上の他のすべてのリソースは HTTPS に対応していますか?

開始する前に、HTTPS が正常に機能するためには、ページ上のすべてのリソースが HTTPS に対応している必要があることを忘れないでください。CDN、ソーシャルログイン、ロゴファイル、サードパーティ製の JavaScript、画像、フォント、CSS など、これらすべてが HTTPS で利用可能である必要があります!

注意: ./discourse-setup を実行すると Let’s Encrypt が有効になります。2017 年 3 月以降は、再度このスクリプトを実行し、数回 Enter キーを押してメールアドレスを入力するだけで、必要なテンプレートが追加され、指定したメールアドレスが設定されます。あなたが熟練したシステム管理者であり、そうしない正当な理由がある場合を除き、詳細を読む前に discourse-setup を実行すべきです。(Discourse を非常に古い時期にインストールした場合は、手動で app.yml を編集する必要があるかもしれません。)

注意: Discourse が何らかのリバースプロキシ(例:Cloudflare)を介してアクセスされている場合、この設定は機能しません。

Let’s Encrypt を使用して HTTPS を設定する

1. app.yml を編集する

Discourse の設定ファイルにアクセスします。

cd /var/discourse
nano containers/app.yml
  • 以下のテンプレートを追加します。
    templates:
      - "templates/web.template.yml"
      - "templates/web.ssl.template.yml"
      - "templates/web.letsencrypt.ssl.template.yml"
    

:warning: Discourse はこのサーバー上の唯一の Web サイトですか?

同じサーバー上のポート 80 で他の Web サイトをホストしているため、すでに web.socketed.template.yml を使用している場合は、中断してください。ホストシステム上で Let’s Encrypt クライアントを使用する必要があります。使用されているクライアントが必要なソケットにバインドできないため、検証が失敗します。

2. HTTPS ポートを公開する

HTTPS トラフィックに対して以下のポートが公開されていることを確認します。

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

3. Let’s Encrypt 用のメールアドレスを追加する

Let’s Encrypt の通知用のメールアドレスを挿入します。

env:
  LETSENCRYPT_ACCOUNT_EMAIL: 'your-email@example.com'

4. アプリケーションを再構築する

コンテナを再構築して変更を適用します。

./launcher rebuild app

5. HTTPS を検証する

https://yourdomain.com にアクセスしてサイトを確認します。成功すれば、HTTPS で保護されたサイトが表示されます。

リソースを確認します。

  • アセット(画像、スクリプトなど)が HTTPS 経由で読み込まれていることを確認します。
  • 必要に応じて、ソーシャルログインや CDN を HTTPS 用に再設定します。
  • ブラウザのコンソールに表示されるインセキュアなアセットに関する警告に対処します。

有効な HTTPS 証明書を使用した再構築後、Discourse は自動的に force_https を有効化します。

仕組みは?

このテンプレートは、以下の機能を持つ GitHub - acmesh-official/acme.sh: A pure Unix shell script ACME client for SSL / TLS certificate automation · GitHub を使用しています。

最もシンプルな Let’s Encrypt 無料証明書クライアント用のシェルスクリプト

シンプルかつ強力、習得には 3 分しかかかりません。

純粋な Bash で記述されており、Python、acme-tiny、または Let’s Encrypt 公式クライアントへの依存関係はありません。証明書を取得・更新する自動化スクリプトが 1 つだけあれば十分です。

おそらく、Let’s Encrypt から無料の証明書を自動的に発行・更新するための、最も小さく、最も簡単で、最も賢いシェルスクリプトでしょう。

web.letsencrypt.ssl.template.yml は、コンテナに以下の処理を行うブートスクリプトを追加します。

  1. メインの nginx が起動する前に、ポート 80 で ACME チャレンジを提供する軽量な nginx を起動します。
  2. /var/www/discourse/public をディレクトリとして webroot モードを使用し、RSA (4096 ビット) および ECDSA (ec-256) の Let’s Encrypt 証明書の両方を発行します。
  3. nginx が期待する /shared/ssl/ ディレクトリに証明書をインストールします。同時に、証明書の自動更新用の cron ジョブが設定されます。これにより証明書が自動的に更新されます。証明書が有効期限内であれば何もしません。証明書が期限切れになった場合、設定時に指定したメールアドレス宛に Let’s Encrypt からメールが届きます。
  4. 有効な証明書が取得された場合、force_https を true に設定します。

トラブルシューティング

ログの確認

HTTPS が機能しない場合は、SSL または Let’s Encrypt のエラーについてログを確認します。

./launcher logs app

証明書ファイルの確認

証明書とキーファイルが配置されていることを確認します。

ls -l /var/discourse/shared/standalone/ssl

以下のようなファイルが表示されるはずです。

  • yourdomain.com.cer (RSA)
  • yourdomain.com.key (RSA)
  • yourdomain.com_ecc.cer (ECDSA)
  • yourdomain.com_ecc.key (ECDSA)

証明書の手動更新

自動更新が失敗した場合、証明書を手動で再発行できます。

./launcher enter app
sv stop nginx
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf
LE_WORKING_DIR=/shared/letsencrypt DEBUG=1 /shared/letsencrypt/acme.sh --issue -d example.com -k 4096 -w /var/www/discourse/public
LE_WORKING_DIR=/shared/letsencrypt /shared/letsencrypt/acme.sh --installcert -d example.com --fullchainpath /shared/ssl/example.com.cer --keypath /shared/ssl/example.com.key --reloadcmd "sv reload nginx"
LE_WORKING_DIR=/shared/letsencrypt DEBUG=1 /shared/letsencrypt/acme.sh --issue -d example.com --keylength ec-256 -w /var/www/discourse/public
LE_WORKING_DIR=/shared/letsencrypt /shared/letsencrypt/acme.sh --installcert --ecc -d example.com --fullchainpath /shared/ssl/example.com_ecc.cer --keypath /shared/ssl/example.com_ecc.key --reloadcmd "sv reload nginx"
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf -s stop

クリーンな証明書での再構築

古い証明書ファイルを削除して、最初から再構築します。

rm -rf /var/discourse/shared/standalone/ssl
rm -rf /var/discourse/shared/standalone/letsencrypt
./launcher rebuild app

制限事項

Let’s Encrypt 証明書はドメインと暗号化のみを検証します。所有権や身元を確認するものではないため、一部のブラウザでフラグが立てられる可能性があります。詳細については、Let’s Encrypt コミュニティ を参照してください。

「いいね!」 143
Setting up Let's Encrypt for multisite
How should I enable letsencrypt while discourse is beside other websites
Cant setting SLL (Let's Encrypt) for Discourse
Add to homescreen banner on Android
How to Set Up SSL in Discourse
Setting up SSL with my domain name and Discourse instance
Issue installing on subdomain
Completely automated SSL certificate generation
German 1&1-hosting user experience?
Problem with my SSL certificate
Replacement for whitelist-iframe
Site throws a blank screen after trying to enable LetsEncrypt
Missing file(discourse.conf) when launching after lets encrypt update?
Missing file(discourse.conf) when launching after lets encrypt update?
My discourse has either been hacked or catfished?
Discourse has stopped opening
Using a certificate when Discourse is installed behind a reverse proxy
Can discourse be installed in private mode
My Forum Is showing "Privacy Error" after upgrading SSL certificate
Using a certificate when Discourse is installed behind a reverse proxy
Why my forum not pop-up "Add to Home screen"(PWA) automatically?
Why my forum not pop-up "Add to Home screen"(PWA) automatically?
HTTPS : issue while trying to set up SSL certification
HTTPS : issue while trying to set up SSL certification
SSL received a record that exceeded the maximum permissible length
Discourse site loads via IP but via domain only header
Why is the Apple Touch Icon loaded via HTTP instead of HTTPS?
Defaultish app won't rebuild
Why is the Apple Touch Icon loaded via HTTP instead of HTTPS?
Why is the Apple Touch Icon loaded via HTTP instead of HTTPS?
Defaultish app won't rebuild
Unable to connect Discourse and WordPress
I have a very difficult problem installing ssl - please help
Not able to access site after letsencrypt cert expiry and rebuild due to IPV6
Cannot connect to IP address and no errors in log
Http logo urls after enabling LetsEncrypt
How to install SSL certificate in Discourse
White blank page on mobile app
Cloud installation not working
My forum goes offline after removing https
Trying to use Let's Encrypt + Cloudflare
New user invite links only give ERR_SSL_PROTOCOL_ERROR
[DigitalOcean] hostname having "www" in A records showing blank page
Error at LetsEncrypt validation
Migrate a phpBB3 forum to Discourse
Set Up Let's Encrypt with Second Domain for Existing Discourse Install
Not starting up after rebuild
Port 443 of computer does not appear to be accessible
Make auto-linked URLs use HTTPS
Unable to change domain name
LetsEncrypt certificate not renewing
How to deny request from unauthorized domain pointing to my IP address?
No login is possible after recovery a Discourse Backup on a new server
Letsencrypt issued on every build?
My Discourse is Down. Certificate Issue?
Setup Let’s Encrypt + non-www > www
No connection accepted on http / https after fresh installation on Ubuntu 22.04 LTS
SSL certificate expired and after that - Error 404 Not Found
SSL didn't renew automatically and I can't manually renew it
443 address already in use? Letencrypt
Set up Let’s Encrypt with multiple domains / redirects
Using Discourse with Cloudflare: Best Practices
./launcher rebuild app error bootstrap failed with exit code 125
Set up Let’s Encrypt with multiple domains / redirects
Uncaught ReferenceError: Discourse is not defined due to Cloudflare Rocket Loader
Let's Encrypt SSL Certificate Not Renewing
Uploads paths have 80 port but protocol is https
Bootstrap error during Discourse install: ENOENT - /etc/runit/1.d/letsencrypt
How to install Discourse in the AWS EC2 Instances(Ubuntu Server LTS)?
Question about the email configuration
Discourse-saml: There was an error authorizing your account
Problem in installing Let's Encrypt SSL for www and non-www
Email not sending out after installation. I need help please
Discourse not starting up: nginx: unable to open supervise/ok: file does not exist
Failed to bootstrap: Failure with receiving network data
Error when installing ssl Let's Encrypt
How to adjust dependencies for https?
Clicking links is stuck in click tracking, shows ERR_FAILED
Minimum needed to get LetsEncrypt working on a GCE instance
Can we install discourse in another container distro?
Problem with my SSL certificate
Cant setting SLL (Let's Encrypt) for Discourse
[PAID] setup ssl - Let's encrypt
Error after moving from HTTP to HTTPS
How to renew Let's Encrypt?
ServiceWorker script evaluation failed due to HTTP (not HTTPS)
Defaultish app won't rebuild
Too many redirects after enabling https