LoginSignup
3
1

More than 3 years have passed since last update.

Let's Encrypt の証明書自動更新を有効にしたまま別ドメインにリダイレクトさせる

Last updated at Posted at 2019-09-10

Apache + Let's Encrypt + webroot で SSL サーバ証明書を自動更新させている環境において、証明書の自動更新を有効にしたまま別ドメインにリダイレクトさせたい時の設定方法です。


Apache の VirtualHost 設定

webroot プラグインは、ドキュメントルートの下に一時的に .well-known/acme-challenge というディレクトリを作成し、そこを使って認証作業をしてくれるものです。

ですので、Apache の mod_rewrite を利用し、.well-known/acme-challenge へのリクエスト時のみリダイレクトしないようにしてやれば良いです。以下は…

  • http://example.com/path?queryhttp://example.net/path?query
  • https://example.com/path?queryhttps://example.org/path?query

…とリダイレクトさせる例です。

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /path/to/document/root

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
    RewriteRule ^.*$ http://example.net%{REQUEST_URI} [R=301,L,NE]
</VirtualHost>

<Virtualhost *:443>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /path/to/document/root

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
    RewriteRule ^.*$ https://example.org%{REQUEST_URI} [R=301,L,NE]

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1