サーバ用Raspberry Pi の設定8

 新しくサイトを公開するなら、hhtp ではなく、https でのサービスが必須でしょう。

 しかし、正式な https には、証明機関の証明書が必要になります。

参考:https://qiita.com/HO_Pollyanna/items/aee45b25e2318d39157b

 Let’s Encrypt というものを使って、https で公開できるようにします。

 まず、ルータで 443 番ポートを開けておきます。
 ルータの設定画面で WAN からくる 443 番ポートのデータを Apache が動いているマシンの IP アドレスへ振り分けるように設定すれば OK です。

 Certbot クライアントを使うようなので、インストールします。

$ sudo apt-get install certbot python-certbot-apache

 実行して登録と証明書の取得します。

$ sudo certbot certonly
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
1: Apache Web Server plugin (apache)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Select the appropriate number [1-3] then [enter] (press 'c’ to cancel): 3
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c’ to cancel): xxxxx@sirius10.dip.jp

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
(A)gree/(C)ancel: A

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let’s Encrypt project and the non-profit
organization that develops Certbot? We’d like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
(Y)es/(N)o: y
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c’ to cancel): sirius10.dip.jp
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for sirius10.dip.jp
Input the webroot for sirius10.dip.jp: (Enter 'c’ to cancel): /var/www/sirius10
Waiting for verification…
Cleaning up challenges

IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/sirius10.dip.jp/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/sirius10.dip.jp/privkey.pem
Your cert will expire on 2021-06-02. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
“certbot renew"
– Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
– 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

 これで、証明書の取得はできたはずなので、apache を設定していきます。
 参考にしたページは仮想サイトではないので、ちょっと違います。
 /etc/apache2/sites-available に移動し、default-ssl.conf を参考に、sirius10.dip.jp-ssl.conf を作成します。

ssl を有効にします。

$ sudo a2enmod ssl
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
systemctl restart apache2

サイトを有効にします (sites-enabled へリンクを貼っても OK)

$ sudo a2ensite sirius10.dip.jp-ssl

Apache を再起動します。

$ sudo service apache2 restart

 エラーが出てしまいました。sudo systemctl status apache2.service で詳細が見れます。
 conf ファイルのエラーでした。

 Apache を再起動して、https でアクセスしてみます。
大丈夫でした。

web サイト

Posted by sirius