Let’s EncryptのSSL証明書をDNS認証で発行する-openlitespeed

SSLとして使っているLet's Encryptですが、一点だけ困った点があります。/.well-known/acme-challenge/でエラーとなるケースが多いという点です。
nginx等は対策などがでていますがopenlitespeedだと中々・・・apacheと互換あるのでいけるのでは?と思ったのですがPythonを使っているせいかわからない事もあり調べて見ました。
環境
今回の環境は以下になります
- WEBサーバー:openlitespeed
- 言語:Python3.6.x
- フレームワーク:Bottle
となります。フレームワークを使っているとルーティングをしているため/.well-known/acme-challenge/でエラーが出ました。nginxなどの場合はserver.confとかに対応策がありますがopenlitespeedの場合は残念ながらありませんでした。
結論:DNS認証をする
Let's EncryptにはDNS認証もあり、そっちのほうが早いなと思いました。コマンドは以下になります。
[c]
certbot certonly --manual -d xxxx.com --preferred-challenges dns
# xxxx.comはドメイン名になります
[/c]
DNS認証はテキストをレコードに追記する

DNS認証の場合は以下の様な画面になります
そこに記載されているテキストをレコードに書き込む事で認証できます
[c]
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for kantsuri.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:
#Yesを選択
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.kantsuri.com with the following value:
ekf3gZtxSDdWuD3JwR9Ok0tZms9HzykFmSImqyTkYHU
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
#ekから始まるテキストをいれる。これはサンプルなので実際は画面に表示されたのをいれてください。
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/kantsuri.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/kantsuri.com/privkey.pem
Your cert will expire on 2020-07-11. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
[root@ik1-337-28649 ~]#
[/c]
注意
- レコードがドメインに反映されるまでは画面はそのままにしていてください。反映されたらエンターを押してください
- ホスト名は_acme-challenge となります
やってみたけど失敗した例
Pythonを使っていて、フレームワークにbottleを使っていました。そこで/.well-known/acme-challenge/がアクセスできないのでできるようにルーティングを追加しました。
[python]
@route('/.well-known/acme-challenge/<filename>')
def well_known_dir(filename):
return template('.well-known/acme-challenge/test.html')
[/python]
問題無くアクセスできたけど、結局SSLの証明書は取得できなかったです。
個人支援・寄付について
サイトラボでは個人支援・寄付を受けております。ご協力いただける方はお願いいたします。当サイトではビットコインで受け付けております。
- ビットコイン:3LHnADwZwUbic2L45EnVJEykiG6KfbqrwS