当記事はアフィリエイト広告を利用しています
【Ubuntu編】Xserver VPSに無料SSL「Let's Encrypt」をインストールする方法

【Ubuntu編】Xserver VPS(エックスサーバーVPS)に無料SSL「Let's Encrypt」をインストールする方法

こちらのページでは、Xserver VPSにインストールしたUbuntuのサーバーに無料SSL「Let's Encrypt」をインストールする方法を説明しています。
WEBサーバーにはApache(アパッチ)を使用しています。

以前はそこそこ手間がかかっていたのですが、現在は意外にサクッと完了するようになっています。
Xserver VPSを利用されている方で、Ubuntuサーバーへの「Let's Encrypt」のインストール方法をお探しの方はお読みください。

無料SSL「Let's Encrypt」のインストール方法

Certbotをインストール
# sudo apt-get install -y certbot python3-certbot-apache
Certbotを実行
# sudo certbot --apache


この後、対話形式で作業を進めていきます。
以下のように返答していきましょう。

UbuntuにSSLをインストール
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel):
→「メールアドレス」を入力してEnter

UbuntuにSSLをインストール
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:
→「Y」を選択してEnter

UbuntuにSSLをインストール
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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:
→「N」を選択してEnter

UbuntuにSSLをインストール
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: x162-43-4-61.static.xvps.ne.jp
2: sabameijin-dev.com
3: www.sabameijin-dev.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
→何も選択せずにEnter
※特定のホストのみにSSLを設定する場合には番号を指定してください。

これで完了です。
このようなメッセージが表示されればOKです。
UbuntuにSSLをインストール

途中で以下のような質問をされることもあります。
※ホストの設定状況などにより対話の内容が異なります。

UbuntuにSSLをインストール
We were unable to find a vhost with a ServerName or Address of x162-43-4-61.static.xvps.ne.jp.
Which virtual host would you like to choose?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: apache2.conf | Multiple Names | | Enabled
2: 000-default.conf | | | Enabled
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
→「2」を選択してEnter

UbuntuにSSLをインストール
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
これはHTTPをHTTPSへリダイレクトさせるかどうかの設定で、「2」を選択するとHTTPSへ強制的にリダイレクトされてしまいます。
それでも問題はないですが、個人的には「1」を選択しておいて、あとで「.htaccess」などを使って自身で設定することをおすすめします。

これで「Let's Encrypt」のインストールは完了です!

HTTPSでのアクセスチェック

インストールが完了したら、最後にHTTPSのURLへアクセスして画面が正常に表示されるかもチェックしておきましょう。
インストールまで正常に終了しても、途中で何かしらの失敗をしていることもあるの気を付けてください。

SSL証明書の更新について

「Let's Encrypt」を利用する場合、証明書の期限が3ヶ月とかなり短くなっています。
その為、3ヶ月ごとに更新作業が必要で、以前はCronを使って自動更新されるように設定を行っていました。

ですが、現在はCertbotに自動更新機能が追加されたので、特に何も設定する必要はありません。

念の為にタイマーをチェックして、自動更新の設定が有効になっているかだけ確認しておきましょう。

# sudo systemctl status certbot.timer

このようにメッセージが出ていればOKです

● certbot.timer - Run certbot twice daily
Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Mon 2022-11-07 21:39:41 JST; 1h 13min ago
Trigger: Tue 2022-11-08 10:27:01 JST; 11h left

Nov 07 21:39:41 x162-43-4-61 systemd[1]: Started Run certbot twice daily.

\Xserver VPSのお申込みはコチラ↓/
圧倒的性能!圧倒的コスパ!月額830円~のVPS!
おすすめの記事