0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apacheで複数ドメインの接続を受け付ける設定と証明書の作り方

Posted at

概要

自宅サーバを公開するにあたって、
IPv4リーチャビリティはルーターメーカーのダイナミックDNSサービスによって、
IPv6リーチャビリティはOPEN IPv6 ダイナミック DNS for フレッツ・光ネクストによって確保する。
そのときのApacheの設定と、Let's Encryptの証明書の作り方のメモ。

Apacheの設定

ServerAalias ディレクティブを使う。
こんなかんじ

httpd.conf
<VirtualHost *:443>
(中略)
ServerName (メインとしたいドメイン名)
ServerAlias (サブとしたいドメイン名)
(後略)
</VirtualHost>

メインとサブの違いはほぼないっぽい。
メインが証明書と秘密鍵のファイル名に使われるくらい。

証明書の作り方

Certbotがやはり一番楽。
Apacheの設定を済ませたら、 certbot コマンドを実行するだけでOK。
なお、下記のログはすでに1個目のドメインを設定済みのときのもの。
新規で設定する場合は出力が違うハズ。

$ sudo certbot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: (ドメイン名1)
2: (ドメイン名2)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): ←そのままエンター

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You have an existing certificate that contains a portion of the domains you
requested (ref: /etc/letsencrypt/renewal/(ドメイン名1).conf)

It contains these names: (ドメイン名1)

You requested these names for the new certificate: (ドメイン名1),(ドメイン名2).

Do you want to expand and replace this existing certificate with the new
certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(E)xpand/(C)ancel: e
Renewing an existing certificate for (ドメイン名1) and (ドメイン名2)
Deploying Certificate to VirtualHost /etc/apache2/sites-enabled/000-default-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-enabled/000-default-le-ssl.conf
Enhancement redirect was already set.
Enhancement redirect was already set.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Your existing certificate has been successfully renewed, and the new certificate
has been installed.

The new certificate covers the following domains: https://(ドメイン名1) and https://(ドメイン名2)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/(ドメイン名1)/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/(ドメイン名1)/privkey.pem
   Your certificate will expire on 2022-07-02. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:
   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

感想

certbot楽すぎだし、IPv6 onlyなドメインでも普通に対応してくれてるの嬉しい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?