Apache

Let’s Encryptで無料SSLの新規取得の方法が簡単だった

ssl-secure
o_wani
この記事は作成から5年以上経過しているため、内容が古くなっている可能性があります。

前の手順が古かったので更新しておきます。Let’s Encryptで無料SSLの新規取得する手順がすごく簡単になりましたね。自分が知らなかっただけかもしれませんが、この記事を見て、新規取得する誰かのためにメモします。

【動作確認環境】
・AWSのEC2
・CentOS7(AmazonLinuxではない)
・Apache2.4

【前提条件】
・DNSレコードをSSL証明書設置予定のサーバに向けておくこと
・バーチャルホストの設定(http)をしておくこと
・サーバにgitをインストールしておくこと
・mod_sslをインストールしておくこと

gitでClone

git clone https://github.com/certbot/certbot

cerbot-autoコマンド実行

cd certbot
sudo ./certbot-auto

必要なパッケージがインストールされます。その後メールアドレスの入力などを求められます。下記で入力する内容は各自の環境に置き換えてください。

証明書有効期限のアラートメールが届きますので入力すると良いと思います:「info@54.249.216.6」

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): info@owani.net

規約に同意して進める:「A」

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

EFF関連の情報は不要なので:「N」

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: N

今回証明書を取得するドメインの番号を選びます:「1」

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: owani.net
2: test.owani.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1

設定ファイルが作成され、httpでのアクセスは今後httpsにリダイレクトをするかどうか聞かれます。

DNSレコードの向き先が、該当のサーバに向いていないと、ここで認証エラーになります。

httpでアクセスしてきたときに、httpsへリダイレクトの設定をするかどうか、リダイレクトする場合:「2」

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for owani.net
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/vhost-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/vhost-le-ssl.conf
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):2

無事設定完了です。

SSLの設定は上記の場合、/etc/httpd/conf.d/vhost-le-ssl.confというファイルに記載されました。

このとき、すでにあるバーチャルホストの設定(80)を参照して、SSLの設定(443)ファイルが作成されると思います。のでhttp用のバーチャルホストの設定は各自で事前に準備ください。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://54.249.216.6
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=owani.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cerbot-autoコマンドを実行するだけでした。とても簡単でびっくりです。。証明書の更新もこのコマンドで行いますので、更新の場合もまたメモします。

参考までに【前回記事】
無料SSL証明書「Let’s Encrypt」をAmazon EC2で使用する

STAFF
o_wani
o_wani
スタッフ
大学卒業後、15年間WEB業界で働く。現在はマネジメントに従事していますが、ChatGPTの登場に触発され、このブログを再開。AIをパートナーに、自分で手を動かして実装する楽しさと喜びを再発見中。時代が変わりつつある中でも、陳腐化しない情報発信も目指しています。
記事URLをコピーしました