以前、「Let's Encrypt でサイトを SSL 化する」というエントリーを書きましたが、
Django などのフレームワークを使っている(厳密にはアプリケーション内でばりばりルーティングしている)サイトに
対して Let's Encrypt のサーバー証明書を発行するときにちょっと躓いたのでメモを残しておきます。
・すでに Django サイトが動いている状態
・ Web サーバーに Apache を使っていること
$ certbot-auto certonly --webroot -w /path/to/webroot -d 4to.pics --email=xxxx@4to.pics
これは certbot-auto コマンドが指定したドメイン直下にファイルを生成し、そこにアクセスを試みることでサイトの管理者を確認するという方法を取っているためです。
html, css, jpg のような静的ファイルに対して、 {project root}/static/ のパスが割り当てられています。そしてその静的ファイルにアクセスするには https://4to.pics/static/{any_file} などにする必要がありますが、上記コマンドでアクセスがあるのは /.well-known/acme-challenge/{token} のような URL となりますので、 404 が返ってしまいます。
$ certbot-auto certonly --webroot -w /path/to/webroot -d 4to.pics --email=xxxx@4to.pics
... (中略)
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: 4to.pics
Type: unauthorized
Detail: Invalid response from
http://4to.pics/.well-known/acme-challenge/u40YX3ysycwdVJ1-ukQNI-eMVF__atkK1JzsAEqKJmA:
"<!DOCTYPE html><html lang="en"><head><meta
charset="utf-8"/><title>404 Page not
Found</title></head><body><h1>404 Page not Found"
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.
An unexpected error occurred:
There were too many requests of a given type :: Error creating new authz :: Too many failed authorizations recently.
settings.py
# 以下追記
CERT_ROOT = os.path.join(BASE_DIR, '.well-known')
CERT_URL = '/.well-known/'
# 以下追記
urlpatterns += static.static(settings.CERT_URL, document_root=settings.CERT_ROOT)
# 以下追記
# プロジェクトルートのパスは -w オプションで指定したパスと同じ
Alias /.well-known/ /path/to/project/root/.well-known/
<Location /.well-known/>
Options -Indexes
</Location>
Apache の再起動
$ sudo /etc/init.d/httpd graceful
証明書の発行
$ certbot-auto certonly --webroot -w /path/to/webroot -d 4to.pics --email=xxxx@4to.pics
Requesting to rerun /usr/local/bin/certbot-auto with root privileges...
... (中略)
Performing the following challenges:
http-01 challenge for 4to.pics
Using the webroot path /path/to/webroot for all unmatched domains.
Waiting for verification...
Cleaning up challengesIMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/4to.pics/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/4to.pics/privkey.pem
Your cert will expire on 2018-03-07. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto 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
うまく生成できました。
あとは証明書のパスを ssl.conf に書くだけです。以前紹介した工程と全く同じで大丈夫。
mac に pip をインストールする
mac は標準で python が入っていますが、パッケージ管理の pip がインストールされていないので入れてみました。
2017/05/26 09:00
[GAS] Google Drive の特定フォルダ配下のフォルダ・ファイルの権限を一括で移譲する
Google Drive の特定フォルダ配下のファイル・フォルダの権限を一括で移譲するツールを Google Apps Script で作りました。
2018/11/10 15:54
[Windows] Ophcrack を使ってユーザーパスワードを解析する方法
家族で使っていた Windows7 のログインパスワードを忘れたため、Ophcrack を使って解析したときの記録です。
2017/09/30 21:00
[shell] フォルダ内にある大量の ZIP ファイルをまとめて解凍する
とある ZIP を解凍すると中に大量の ZIP が居たときに幸せになれるコマンドを紹介します
2018/06/19 23:45
[MySQL] データファイルから DB を復元する
先日 MySQL が再起動できなくなる問題が発生し、急遽データファイル(.frm, .ibd)から復元しました
2018/11/25 12:44