{"id":146,"date":"2019-05-10T22:06:28","date_gmt":"2019-05-10T13:06:28","guid":{"rendered":"https:\/\/doc-sin.life\/?p=146"},"modified":"2019-05-10T22:06:28","modified_gmt":"2019-05-10T13:06:28","slug":"post-146","status":"publish","type":"post","link":"https:\/\/doc-sin.life\/?p=146","title":{"rendered":"Lightsail \u3067 Let&#8217;s Encrypt \u306e \u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9SSL \u8a3c\u660e\u66f8\u3092\u81ea\u52d5\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u305f"},"content":{"rendered":"\n<p>Amazon Lightsail \u3067 Let&#8217;s Encrypt \u306e\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9 SSL \u8a3c\u660e\u66f8\u3092\u81ea\u52d5\u3067\u66f4\u65b0\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2>\u3044\u304d\u306a\u3057\u7d50\u8ad6<\/h2>\n\n\n\n<p>\u7d50\u8ad6\u304b\u3089\u8a00\u3046\u3068\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u73fe\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002Amazon Lightsail \u306e<a href=\"https:\/\/lightsail.aws.amazon.com\/ls\/docs\/ja_jp\/articles\/amazon-lightsail-using-lets-encrypt-certificates-with-wordpress\">\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a> \u3067\u306f\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u8a3c\u660e\u66f8\u3092\u53d6\u5f97\u3057\u3066\u304a\u308a\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u8a3c\u660e\u66f8\u306e\u66f4\u65b0\u306b\u306f\u4e00\u624b\u9593\u5fc5\u8981\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cat \/etc\/cron.d\/root\n00 03 01 * *  root certbot renew \\\n--manual --preferred-challenges dns \\\n--manual-public-ip-logging-ok \\\n--manual-auth-hook certbot-dns-auth.sh \\\n--manual-cleanup-hook certbot-dns-clean.sh \\\n--post-hook '\/opt\/bitnami\/ctlscript.sh restart' \\\n&gt;&gt; \/var\/log\/certbot 2&gt;&amp;1<\/code><\/pre>\n\n\n\n<p>manual-auth-hook \u3068 manual-cleanup-hook \u3067\u6307\u5b9a\u3057\u3066\u3044\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cat \/usr\/bin\/certbot-dns-auth.sh\n#!\/bin\/bash\n\nexport AWS_ACCESS_KEY_ID=*******************\nexport AWS_SECRET_ACCESS_KEY=*******************\n\necho '{\"name\": \"_acme-challenge.'${CERTBOT_DOMAIN}'\",\"target\": \"\\\"'${CERTBOT_VALIDATION}'\\\"\",\"type\": \"TXT\"}' | jq . &gt; domain-entry.json\n\n\/usr\/local\/bin\/aws lightsail create-domain-entry \\\n  --domain-name ${CERTBOT_DOMAIN} \\\n  --domain-entry file:\/\/domain-entry.json \\\n  --region us-east-1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cat \/usr\/bin\/certbot-dns-clean.sh\n#!\/bin\/bash\n\nexport AWS_ACCESS_KEY_ID=*******************\nexport AWS_SECRET_ACCESS_KEY=*******************\n\necho '{\"name\": \"_acme-challenge.'${CERTBOT_DOMAIN}'\",\"target\": \"\\\"'${CERTBOT_VALIDATION}'\\\"\",\"type\": \"TXT\"}' | jq . &gt; domain-entry.json\n\n\/usr\/local\/bin\/aws lightsail delete-domain-entry \\\n  --domain-name ${CERTBOT_DOMAIN} \\\n  --domain-entry file:\/\/domain-entry.json \\\n  --region us-east-1<\/code><\/pre>\n\n\n\n<h2>\u3084\u3063\u3066\u307f\u305f\u3053\u3068<\/h2>\n\n\n\n<p>Let&#8217;s Encrypt \u306e\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9 SSL \u8a3c\u660e\u66f8\u3092\u66f4\u65b0\u3059\u308b\u306b\u306f DNS \u8a8d\u8a3c\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>\u306a\u304a\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u8a3c\u660e\u66f8\u306e\u53d6\u5f97\u306e\u969b\u306b\u306f\u3001\u5fc5\u305a DNS-01 Challenge \u3092\u4f7f\u7528\u3057\u305f\u8a8d\u8a3c\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30c9\u30e1\u30a4\u30f3\u540d\u306e\u7ba1\u7406\u6a29\u3092\u6709\u3057\u3066\u3044\u308b\u3053\u3068\u306e\u8a3c\u660e\u306e\u305f\u3081\u306b\u3001DNS \u306b\u304a\u3051\u308b TXT \u30ec\u30b3\u30fc\u30c9\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u3066\u3044\u307e\u3059\u3002<\/p><cite><a href=\"https:\/\/free-ssl.jp\/blog\/2018-03-14.html\">https:\/\/free-ssl.jp\/blog\/2018-03-14.html<\/a><br \/><\/cite><\/blockquote>\n\n\n\n<p>\u901a\u5e38\u3067\u3042\u308c\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u3092 cron \u306a\u3069\u3067\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u81ea\u52d5\u3067\u66f4\u65b0\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u304c\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u8a3c\u660e\u66f8\u306e\u5834\u5408\u306f\u3001\u521d\u56de\u53d6\u5f97\u6642\u3068\u540c\u3058\u3088\u3046\u306b DNS \u30ec\u30b3\u30fc\u30c9\u306e\u767b\u9332\u306e\u4e00\u624b\u9593\u304c\u5fc5\u8981\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>certbot renew &#8211;pre-hook &#8220;service nginx stop&#8221; &#8211;post-hook &#8220;service nginx start&#8221;<\/p><cite><a href=\"https:\/\/free-ssl.jp\/docs\/using.html#renew-subcommand\">https:\/\/free-ssl.jp\/docs\/using.html#renew-subcommand<\/a><\/cite><\/blockquote>\n\n\n\n<p>\u521d\u56de\u53d6\u5f97\u6642\u306f\u5bfe\u8a71\u30e2\u30fc\u30c9\u3067\u30ec\u30b3\u30fc\u30c9\u306e\u5024\u3092\u6307\u5b9a\u3055\u308c\u767b\u9332\u3057\u305f\u304c\u3001\u305d\u308c\u3092\u3069\u3046\u3084\u3063\u3066\u81ea\u52d5\u306b\u3059\u308b\u304b\u3068\u8a00\u3046\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u66f4\u65b0\u6642\u306b\u30ec\u30b3\u30fc\u30c9\u306e\u5024\u3092\u53d7\u3051\u53d6\u3063\u3066\u51e6\u7406\u3092\u8d70\u3089\u305b\u308b\u8d85\u4fbf\u5229\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u305d\u3061\u3089\u3092\u4f7f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>Certbot allows for the specification of pre and post validation hooks when run in manual mode. The flags to specify these scripts are&nbsp;<code>--manual-auth-hook<\/code>&nbsp;and&nbsp;<code>--manual-cleanup-hook<\/code>&nbsp;respectively and can be used as follows:<\/p><cite><a href=\"https:\/\/certbot.eff.org\/docs\/using.html#pre-and-post-validation-hooks\">https:\/\/certbot.eff.org\/docs\/using.html#pre-and-post-validation-hooks<\/a><\/cite><\/blockquote>\n\n\n\n<p>\u5f53\u30c9\u30e1\u30a4\u30f3 doc-sin.life \u306f Lightsail \u306e DNS \u3067\u7ba1\u7406\u3057\u3066\u3044\u308b\u306e\u3067 aws cli \u3092\u4f7f\u3063\u3066 DNS \u30ec\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<h3>aws cli \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb <\/h3>\n\n\n\n<p>Lightsail \u306e wordpress \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b aws cli \u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\u307e\u305a\u306f aws cli \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f AWS \u306e<a href=\"https:\/\/docs.aws.amazon.com\/ja_jp\/cli\/latest\/userguide\/install-linux.html#install-linux-pip\">\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u3092\u53c2\u8003\u306b\u9032\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ curl -O https:\/\/bootstrap.pypa.io\/get-pip.py\n$ sudo python3 get-pip.py\n$ pip3 --version\npip 19.1.1 from \/usr\/local\/lib\/python3.5\/dist-packages\/pip (python 3.5)\n$ sudo pip3 install awscli --upgrade\n$ aws --version\naws-cli\/1.16.153 Python\/3.5.2 Linux\/4.4.0-1074-aws botocore\/1.12.143<\/code><\/pre>\n\n\n\n<h3>IAMUser \u306e\u4f5c\u6210<\/h3>\n\n\n\n<p>Lightsail \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u306f IAMRole \u3092\u30a2\u30bf\u30c3\u30c1\u51fa\u6765\u306a\u3044\u306e\u3067\u3001DNS \u8a8d\u8a3c\u306b\u5fc5\u8981\u306a Lightsail \u306e DNS \u30ec\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u51fa\u6765\u308b IAMUser \u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30dd\u30ea\u30b7\u30fc\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u6700\u5c0f\u9650\u306b\u7559\u3081\u3066\u304a\u304d\u307e\u3059\u3002\u5bfe\u8c61\u30ea\u30bd\u30fc\u30b9\u306e\u30a2\u30ab\u30a6\u30f3\u30c8 ID \u3068\u30c9\u30e1\u30a4\u30f3\u306e ID \u306f\u7f6e\u304d\u63db\u3048\u308b\u304b\u3001&#8221; * &#8221; \u3067\u3082\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"lightsail:DeleteDomainEntry\",\n                \"lightsail:CreateDomainEntry\"\n            ],\n            \"Resource\": \"arn:aws:lightsail:us-east-1:${ACCOUNT_ID}:Domain\/${DOMAIN_ID}\"\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<h3>\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f5c\u6210<\/h3>\n\n\n\n<p>\u4e0a\u3067\u7d39\u4ecb\u3057\u305f manual-auth-hook \u3068 manual-cleanup-hook \u3067\u5b9f\u884c\u3059\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u5185\u3067\u3001aws lightsail delete-domain-entry \u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306e domain-entry \u306e\u5024\u3092\u4e00\u5ea6  JSON \u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u4f55\u6545\u304b\u3068\u8a00\u3046\u3068 Shorthand \u5f62\u5f0f\u3067\u306f TXT \u30ec\u30b3\u30fc\u30c9\u304c\u3069\u3046\u306b\u3082\u3053\u3046\u306b\u3082\u51fa\u6765\u306a\u304b\u3063\u305f\u304b\u3089\u3067\u3059\u3002A \u30ec\u30b3\u30fc\u30c9\u306e\u5834\u5408\u306f\u5834\u5408\u306f\u554f\u984c\u306a\u3044\u306e\u3067\u3059\u304c\u3001TXT \u30ec\u30b3\u30fc\u30c9\u306e\u5834\u5408\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u4f5c\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ \/usr\/local\/bin\/aws lightsail delete-domain-entry --domain-name doc-sin.life --domain-entry name=txt.doc-sin.life,target=abc123,type=TXT --region us-east-1\n\nAn error occurred (InvalidInputException) when calling the DeleteDomainEntry operation: Input error: Target should be enclosed in quotation marks: abc123.<\/code><\/pre>\n\n\n\n<p>\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u56f2\u3081\u3063\u3066\u8a00\u3063\u3066\u3044\u308b\u306e\u306f\u5206\u304b\u308b\u306e\u3067\u3059\u304c\u3001\u3044\u308d\u3044\u308d\u8a66\u884c\u932f\u8aa4\u3057\u3066\u306e\u3067\u3059\u304c\u99c4\u76ee\u3060\u3063\u305f\u306e\u3067\u4eca\u306e\u5f62\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h3 id=\"mce_13\">\u624b\u52d5\u5b9f\u884c\u3057\u3066\u307f\u308b<\/h3>\n\n\n\n<p>\u6750\u6599\u306f\u63c3\u3063\u305f\u306e\u3067\u624b\u52d5\u5b9f\u884c\u3092\u3057\u3066\u307f\u308b\u3002\u901a\u5e38 Let&#8217;sEncrypt \u306f\u8a3c\u660e\u66f8\u306e\u671f\u9650\u304c\uff11\u30f6\u6708\u4ee5\u4e0a\u6b8b\u3063\u3066\u3044\u308b\u3068\u66f4\u65b0\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u3067 &#8211;force-renewal \u3092\u3064\u3051\u3066\u5f37\u5236\u7684\u306b\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo certbot renew --manual --preferred-challenges dns --manual-public-ip-logging-ok --manual-auth-hook certbot-dns-auth.sh --manual-cleanup-hook certbot-dns-clean.sh --post-hook '\/opt\/bitnami\/ctlscript.sh restart' --force-renewal\nSaving debug log to \/var\/log\/letsencrypt\/letsencrypt.log\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nProcessing \/etc\/letsencrypt\/renewal\/doc-sin.life.conf\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nPlugins selected: Authenticator manual, Installer None\nRenewing an existing certificate\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nnew certificate deployed without reload, fullchain is\n\/etc\/letsencrypt\/live\/doc-sin.life\/fullchain.pem\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\nCongratulations, all renewals succeeded. The following certs have been renewed:\n  \/etc\/letsencrypt\/live\/doc-sin.life\/fullchain.pem (success)\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nRunning post-hook command: \/opt\/bitnami\/ctlscript.sh restart\nOutput from ctlscript.sh:\n\/opt\/bitnami\/apache2\/scripts\/ctl.sh : httpd stopped\n\/opt\/bitnami\/php\/scripts\/ctl.sh : php-fpm stopped\n\/opt\/bitnami\/mysql\/scripts\/ctl.sh : mysql stopped\n\/opt\/bitnami\/mysql\/scripts\/ctl.sh : mysql  started at port 3306\n\/opt\/bitnami\/php\/scripts\/ctl.sh : php-fpm started\n\/opt\/bitnami\/apache2\/scripts\/ctl.sh : httpd started at port 80\n\nError output from ctlscript.sh:\nSyntax OK\nSyntax OK<\/code><\/pre>\n\n\n\n<p>\u554f\u984c\u306a\u304f\u66f4\u65b0\u51fa\u6765\u305f\u306e\u3067\u3001\u4eca\u5b9f\u884c\u3057\u305f\u3082\u3092 cron \u306b\u767b\u9332\u3057\u6708\u30a4\u30c1\u3067\u5b9f\u884c\u3055\u305b\u3066\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Amazon Lightsail \u3067 Let&#8217;s Encrypt \u306e\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9 SSL \u8a3c\u660e\u66f8\u3092\u81ea\u52d5\u3067\u66f4\u65b0\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":159,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"","_original_post":""},"categories":[9],"tags":[19,40,57],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/doc-sin.life\/wp-content\/uploads\/2019\/05\/https-3344700_1920.jpg?fit=1920%2C768&ssl=1","_links":{"self":[{"href":"https:\/\/doc-sin.life\/index.php?rest_route=\/wp\/v2\/posts\/146"}],"collection":[{"href":"https:\/\/doc-sin.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/doc-sin.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/doc-sin.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/doc-sin.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":0,"href":"https:\/\/doc-sin.life\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/doc-sin.life\/index.php?rest_route=\/wp\/v2\/media\/159"}],"wp:attachment":[{"href":"https:\/\/doc-sin.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/doc-sin.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/doc-sin.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}