概要
無料でSSL証明書が使えるということで個人で使ったり、
ローカルの開発環境にSSLを入れられると便利だなと思い、調べてみる。
<検証環境>
- 余っているドメインがある(どこにも使ってない)
- 主にローカル環境で開発をしている
最近HTTPSのサイトが多くなってきたので、オレオレ証明書ではなく正規の証明書を使いたい。
Let's Encryptの認証方法
Let’s Encryptで証明書の取得を行う場合、以下の方法などで、
ドメインを認証する必要があるようです。
- HTTPによるドメイン認証 (HTTP-01)
- HTTPSによるドメイン認証 (TLS-SNI-01)
- DNSによるドメイン認証 (DNS-01)
今回は、公開しているサイトではないので、以下の方法を検討する。
<DNSによるドメインを認証を方法 (DNS-01)>
認証対象のドメインのサブドメインのTXTレコードにトークンが設定されているかで認証する。
( 2016年01月20日に、DNSによる認証チャレンジをサポート )
例)example.comの証明書を取得する場合
※「 _acme-challenge.example.com 」というサブドメインを追加
※ そのドメインの「 TXTレコード 」にトークンを設定する
certbotインストール
今回は、CentOS7なので以下のコマンドを実行します。
$ sudo yum install -y epel-release
$ sudo yum install -y certbot python-certbot-apache
※ その他のOSの場合は、letsencrypt.jp を参照
certbotコマンドでの設定
コマンド実行
DNSでの認証を試してみる。
※「--preferred-challenges」オプションで「dns-01」を指定。
$ sudo certbot certonly \
--manual \
--domain www.example.com \
--email hoge@example.com \
--agree-tos \
--manual-public-ip-logging-ok \
--preferred-challenges dns-01
・
・
・
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.www.example.com with the following value:
testiKfugafugaqW2-qF_W3doiJhogehogehogeyNCRkY
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
※ コマンドを実行したらトークンが表示されるのでDNSを登録する
※ DNSの設定が反映されるまで、そのまま放置(約1時間ぐらい?)
DNS設定情報
・Host : _acme-challenge.example.com
・Type : TXTレコード
・Value: testiKfugafugaqW2-qF_W3doiJhogehogehogeyNCRkY
DNS設定の反映確認
DNS設定が反映されているか下記コマンドなどで確認する
$ dig -t txt _acme-challenge.example.com
DNS設定が反映されたら
実行中のコマンドで「Enter」を押して進む。
Press Enter to Continue
Waiting for verification...
Resetting dropped connection: acme-v01.api.letsencrypt.org
Resetting dropped connection: acme-v01.api.letsencrypt.org
Cleaning up challenges
Failed authorization procedure. www.example.com (dns-01):
urn:acme:error:connection ::
The server could not connect to the client to verify the domain ::
DNS problem: NXDOMAIN looking up TXT for _acme-challenge.www.example.com
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: www.example.com
Type: connection
Detail: DNS problem: NXDOMAIN looking up TXT for
_acme-challenge.www.example.com
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address. Additionally, please check that
your computer has a publicly routable IP address and that no
firewalls are preventing the server from communicating with the
client. If you're using the webroot plugin, you should also verify
that you are serving files from the webroot path you provided.
TXTレコードだけ設定したのではエラーになるみたい...
<エラー内容>
ドメイン名が正しく入力され、
そのドメインのDNSにAレコードに正しいIPアドレスが含まれていることを確認してください。
ドメインは持っているが勉強用のローカル環境なのでAレコードを指定するサーバがない・・・
さすがにドメイン持っているだけでは、証明書の発行は難しそうですね。
時間のある時に、また調べてみます。
参考サイト
- CertbotでDNSによる認証(DNS-01)で無料のSSL/TLS証明書を取得する
- Github - certbot
- Let's Encrypt 総合ポータル
- 非公開サイトをLet's EncryptなDockerコンテナでSSL化
- 無料SSL証明書「Let’s Encrypt」を試してみた
- Let's Encryptでサブドメインをまとめてhttpsにする
- DockerとLet's encryptを組み合わせて運用する
- Let's EncryptのDNS-01を使用して無料のSSL証明書をWebサーバなしで取得する
- willfarrell/letsencrypt
- 複数のWebアプリを1サーバーのDockerを使ってSSL対応のサブドメインで簡単に運用する
- はじめてのDocker その2 〜SSLに対応した複数ドメイン環境を作る方法〜