最終ステージ:SSL化

ポートの開放

まず、

[root@chimaira ~]# firewall-cmd --add-service=https  --permanent
success
[root@chimaira ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: cockpit dhcpv6-client ftp http smtp ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@chimaira ~]#

変更が反映されてないので焦った。zoneが必須かと思ったがそいういうことではない(デフォルトゾーンが使われる)。

[root@chimaira ~]# firewall-cmd --zone=public --add-service=https  --permanent
Warning: ALREADY_ENABLED: https
success
[root@chimaira ~]#

リロード忘れていた(やらかしアルアル)。

firewall-cmd --reload
firewall-cmd --list-service

httpsが表示された。パーマネントな記録を見るには、

[root@chimaira ~]# cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <service name="cockpit"/>
  <service name="ftp"/>
  <service name="http"/>
  <service name="smtp"/>
  <service name="https"/>
</zone>
[root@chimaira ~]#
certbotを使ってnginx設定

certbot --nginx が「プラグインがない」という理由で動かない。python2-certbot-nginx, python-certbot-nginx をインストールしようとしたがダメ。epelが必要かと思い、

yum install epel-release
yum --enablerepo=epel install certbot python2-certbot-nginx

これも失敗。

[root@chimaira ~]# yum --enablerepo=epel info python2-certbot-nginx
Last metadata expiration check: 2:29:17 ago on Fri 10 Sep 2021 05:45:40 AM JST.
Error: No matching Packages to list
[root@chimaira ~]#

実はpytho2が廃止されたようで、

[root@chimaira ~]# yum --enablerepo=epel info python3-certbot-nginx
Last metadata expiration check: 2:33:44 ago on Fri 10 Sep 2021 05:45:40 AM JST.
Available Packages
Name         : python3-certbot-nginx
Version      : 1.18.0
Release      : 1.el8
Architecture : noarch
Size         : 85 k
Source       : python-certbot-nginx-1.18.0-1.el8.src.rpm
Repository   : epel
Summary      : The nginx plugin for certbot
URL          : https://pypi.python.org/pypi/certbot-nginx
License      : ASL 2.0
Description  : Plugin for certbot that allows for automatic configuration of nginx

[root@chimaira ~]#

yum install python3-certbot-nginx でインストール。その後 certbot --nginx を実行。あっさり成功。

/etc/letsencrypt/ に設定が入る。nginxのオリジナル設定の保存を忘れたが、listen 80 が listen 443 ssl になっていて、幾つか設定項目〈ディレクティブ〉が追加されていた。/etc/nginx/conf.d/ を見れば分かる。grep certbot するといい。