6
3

More than 3 years have passed since last update.

ドメイン取得せずにEC2(Amazon Linux 2)でLet's EncryptのSSL証明書発行したらどうなるか試したらやっぱり失敗する

Last updated at Posted at 2020-04-03

タイトル通りなんですけど、試してみたらやっぱり発行できないです。
やったことをつらつらと書いていきます。

EC2はAmazon Linux 2で立てた

とりあえずEC2サーバを立てました。
OSはAmazon Linux 2です。
セキュリティグループは以下に設定。
certbotを使用するので、ちゃんとHTTP(80)ポート開けてます。

タイプ プロトコル ポート ソース
HTTP TCP 80 0.0.0.0/0
SSH TCP 22 {自分のIP}
HTTPS TCP 443 0.0.0.0/0

cerbotを使用して証明書発行する

https://certbot.eff.org
cerbotのサイト見るとサーバのソフトウェアとOS選ぶことになるんですけど、OSにはAmazon Linux 2がないわけです。
Amazon Linux 2ってどうすればいいんだと、ここで壁が立ちはだかります。

Amazon Linux 2がない.png

Amazon Linux 2はRHEL 7ベースらしい

いろいろ調べてみるとRHEL 7ベースらしいです。
Amazon LinuxはRedHat準拠なんですね。
あとで出てきますがcerbotインストールするにはEPELリポジトリを有効化する必要があるのですが、以下をみるとAmazon Linux 2はRHEL 7と同じコマンドみたいです。
https://aws.amazon.com/jp/premiumsupport/knowledge-center/ec2-enable-epel/

ソフトウェアはNon of the above、OSはCentOS/RHEL 7で手順を実行する

https://certbot.eff.org/lets-encrypt/centosrhel7-other
この順位従って証明書を発行していきます。

SSHログイン

SSHでEC2に接続します。

ログイン
ssh -i {キーペア証明書のパス} ec2-user@{パブリックDNS}

EPELリポジトリのインストールと有効化

https://aws.amazon.com/jp/premiumsupport/knowledge-center/ec2-enable-epel/
上記に方法が書いてありましたので以下を実行しました。

EPELリポジトリのインストール
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --enable epel

Optionalチャンネルを有効化

Optionalチャンネルを有効化
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

スタンドアロンで発行

今回はまだサーバ立ててないのでスタンドアロンで発行します。
そして本番環境使用するのも申し訳ないのでLet's Encryptのステージング環境を利用します。
--dry-runとつけるとステージング環境をしようするそうです。

証明書を発行
sudo certbot certonly --standalone --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel): 

ドメインを聞かれるのでパブリックDNSのドメインを記載しました。
すると以下のエラーが発生しました。

エラー発生
Obtaining a new certificate
An unexpected error occurred:
The server will not issue certificates for the identifier :: Error creating new order :: Cannot issue for "xxxxxxxxx.compute.amazonaws.com": The ACME server refuses to issue a certificate for this domain name, because it is forbidden by policy
Please see the logfiles in /var/log/letsencrypt for more details.

このドメインは発行できないってことみたいです。

ちゃんとしたい場合はドメインを取得しようね

そういうことですね。
ドメインを取得しない場合は素直にオレオレ証明書を発行しようと思います。
またはNode.jsであればHeroku使っちゃえば証明書発行せずにHTTPS使えるのでそっちですね。

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