「Linux/LetsEncrypt導入」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→証明書取得が出来たら以下ファイルが出来てることを確認) |
(→証明書取得が出来たら以下ファイルが出来てることを確認) |
||
| 行36: | 行36: | ||
==証明書取得が出来たら以下ファイルが出来てることを確認== | ==証明書取得が出来たら以下ファイルが出来てることを確認== | ||
# ls /etc/letsencrypt/live/[ドメイン]/ | # ls /etc/letsencrypt/live/[ドメイン]/ | ||
| − | cert.pem | + | ├── accounts |
| − | chain.pem | + | │ └── acme-v01.api.letsencrypt.org |
| − | fullchain.pem | + | │ └── directory |
| − | privkey.pem | + | │ └── 1111111111111111111111111111111 |
| + | │ ├── meta.json | ||
| + | │ ├── private_key.json | ||
| + | │ └── regr.json | ||
| + | ├── archive | ||
| + | │ └── example.net | ||
| + | │ ├── cert1.pem | ||
| + | │ ├── cert2.pem | ||
| + | │ ├── chain1.pem | ||
| + | │ ├── chain2.pem | ||
| + | │ ├── fullchain1.pem | ||
| + | │ ├── fullchain2.pem | ||
| + | │ ├── privkey1.pem | ||
| + | │ └── privkey2.pem | ||
| + | ├── csr | ||
| + | │ ├── 0000_csr-certbot.pem | ||
| + | │ └── 0001_csr-certbot.pem | ||
| + | ├── keys | ||
| + | │ ├── 0000_key-certbot.pem | ||
| + | │ └── 0001_key-certbot.pem | ||
| + | ├── live | ||
| + | │ └── example.net | ||
| + | │ ├── cert.pem -> ../../archive/example.net/cert2.pem | ||
| + | │ ├── chain.pem -> ../../archive/example.net/chain2.pem | ||
| + | │ ├── fullchain.pem -> ../../archive/example.net/fullchain2.pem | ||
| + | │ └── privkey.pem -> ../../archive/example.net/privkey2.pem | ||
| + | └── renewal | ||
| + | └── example.net.conf | ||
==Too many certificates already issued for exact set of domainsエラー== | ==Too many certificates already issued for exact set of domainsエラー== | ||
2016年7月2日 (土) 14:07時点における版
目次
certbot-autoのインストール
# cd /usr/local # git clone https://github.com/certbot/certbot # cd ./certbot # ./certbot-auto
証明書取得
./certbot-auto certonly --webroot \ -w /var/www/example/public -d example.com \ -m sample@example.com \ --agree-tos
以下エラーが発生する場合はPythonが2.6になってる可能性があるので、Python 2.7を入れる必要がある
./certbot-auto: line 558: virtualenv
-dのオプションに設定した"example.com"にhttpアクセスできることを事前に確認しておく。
Python 2.7のインストール
$ sudo yum install centos-release-scl $ sudo yum install python27 python27-python-tools $ python -V Python 2.6.6 # デフォだと2.6なので以下コマンドで一時的に2.7へ $ sudo scl enable python27 bash $ python -V Python 2.7.8
ログイン時にpythonが2.7.8となるように
# vi /etc/profile.d/enablepython27.sh #!/bin/bash source /opt/rh/python27/enable export X_SCLS="`scl enable python27 'echo $X_SCLS'`"
参考:http://blog.offline-net.com/2016/05/08/apache_24_with_letsencrypt/
証明書取得が出来たら以下ファイルが出来てることを確認
# ls /etc/letsencrypt/live/[ドメイン]/
├── accounts
│ └── acme-v01.api.letsencrypt.org
│ └── directory
│ └── 1111111111111111111111111111111
│ ├── meta.json
│ ├── private_key.json
│ └── regr.json
├── archive
│ └── example.net
│ ├── cert1.pem
│ ├── cert2.pem
│ ├── chain1.pem
│ ├── chain2.pem
│ ├── fullchain1.pem
│ ├── fullchain2.pem
│ ├── privkey1.pem
│ └── privkey2.pem
├── csr
│ ├── 0000_csr-certbot.pem
│ └── 0001_csr-certbot.pem
├── keys
│ ├── 0000_key-certbot.pem
│ └── 0001_key-certbot.pem
├── live
│ └── example.net
│ ├── cert.pem -> ../../archive/example.net/cert2.pem
│ ├── chain.pem -> ../../archive/example.net/chain2.pem
│ ├── fullchain.pem -> ../../archive/example.net/fullchain2.pem
│ └── privkey.pem -> ../../archive/example.net/privkey2.pem
└── renewal
└── example.net.conf
Too many certificates already issued for exact set of domainsエラー
短時間に証明書取得コマンドをリクエストしすぎ。しばらくすると戻る
同一ドメインは週に20個まで
参考:https://community.letsencrypt.org/t/rate-limits-for-lets-encrypt/6769/2
nginx設定に追加
server {
listen 80;
server_name example.net;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443 ssl;
server_name example.net;
ssl_certificate /etc/letsencrypt/live/example.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem;
sslのfirewallを切る
$ sudo vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT $ sudo /etc/rc.d/init.d/iptables restart
nginxのproxyを使ってる場合
server {
listen 80;
server_name example.com;
rewrite ^ https://$http_host$request_uri? permanent;
}
server {
listen 443 ssl;
server_name example.net;
ssl_certificate /etc/letsencrypt/live/example.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.net/privkey.pem;
location / {
proxy_pass http://example.localhost/;
proxy_redirect http:// https://;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^~ /.well-known/acme-challenge/ {
root /var/www/html/public;
}
}
証明書を取る前はssl_certificateと ssl_certificate_keyはコメントアウトしておく
参考:http://qiita.com/ywatai@github/items/a179186a458a42b3c7f0
sslの自動更新
有効期限が90日間しかないので自動更新する必要がある
以下で更新できるが、nginx, apacheなどを再読込しなければならないためcrontabによる手動更新が推奨される様子。
# ./certbot-auto renew
更新を手動で行いnginxの設定を再読込する
# crontab -e
全ドメインを更新するには
0 5 1 * * /usr/local/certbot/certbot-auto renew --force-renew && /etc/rc.d/init.d/nginx reload
個別ドメインを更新するには
0 5 1 * * /usr/local/certbot/certbot-auto certonly --webroot -w /var/www/example -d example.com --renew-by-default && /etc/rc.d/init.d/nginx reload
参考:https://blog.apar.jp/linux/3619/
httpsするにあたって
- scriptなどのhttp記述をhttpsへ書き直す
