﻿{"id":1096,"date":"2016-06-02T20:21:31","date_gmt":"2016-06-02T12:21:31","guid":{"rendered":"http:\/\/zerobox.org\/notes\/?p=1096"},"modified":"2016-06-02T20:21:37","modified_gmt":"2016-06-02T12:21:37","slug":"lets-encrypt-%e7%bb%99%e7%bd%91%e7%ab%99%e5%8a%a0-https-%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/1096.html","title":{"rendered":"Let&#8217;s Encrypt \u7ed9\u7f51\u7ad9\u52a0 HTTPS \u5b8c\u5168\u6307\u5357"},"content":{"rendered":"<section class=\"post-content\">\u524d\u6bb5\u65f6\u95f4\u5728\u5317\u4eac\u8054\u901a3G\u79fb\u52a8\u7f51\u7edc\u4e0b\uff0c\u53d1\u73b0\u81ea\u5df1\u7684\u7ad9\u70b9\u88ab\u8054\u901a\u52ab\u6301\u6ce8\u5165\u6076\u5fc3\u7684\u8bdd\u8d39\u5145\u503c\u5e7f\u544a\uff0c\u51b3\u5b9a\u8ba9\u6211\u7684\u7f51\u7ad9\u5f3a\u5236\u4f7f\u7528 HTTPS\uff0c\u907f\u514d ISP \u52ab\u6301\u3002<\/p>\n<h2 id=\"https\">\u4f7f\u7528 HTTPS \u524d\u7684\u4e00\u4e9b\u7591\u60d1<\/h2>\n<p>\u73b0\u5728\u662f 2016 \u5e74\uff0c\u4f7f\u7528 HTTPS \u5df2\u7ecf\u4e0d\u50cf\u51e0\u5e74\u524d\u662f\u4e00\u4ef6\u6602\u8d35\u7684\u4e8b\u60c5\u3002\u5f53\u7136\u6211\u4e5f\u662f\u81ea\u5df1\u4e86\u89e3\u4e86\u4e00\u5708\u624d\u6d88\u9664\u4e86\u81ea\u5df1\u7684\u7591\u60d1\uff0c\u4e3b\u8981\u662f\uff1a<\/p>\n<ol>\n<li>\u6211\u7684\u7f51\u7ad9\uff08\u4e00\u4e2a\u7b80\u5355\u7684\u535a\u5ba2\uff09\u53ef\u80fd\u6ca1\u5fc5\u8981\u4f7f\u7528 HTTPS<\/li>\n<li>HTTPS \u4f1a\u4e0d\u4f1a\u8ba9\u7f51\u7ad9\u901f\u5ea6\u53d8\u6162\uff1f<\/li>\n<li>HTTPS \u9700\u8981\u82b1\u94b1\u5427\uff1f\u8bc1\u4e66\u597d\u50cf\u4e0d\u4fbf\u5b9c<\/li>\n<li>\u914d\u7f6e\u548c\u7ef4\u62a4 HTTPS \u4ee3\u4ef7\u5f88\u9ad8<\/li>\n<\/ol>\n<p>\u8981\u56de\u7b54\u8fd9\u4e9b\u95ee\u9898\uff0c\u63a8\u8350\u5927\u5bb6\u53bb\u770b\u4e00\u4e0b Google I\/O 2016 \u7684\u89c6\u9891\uff08Youtube\uff09\uff1a<a href=\"https:\/\/www.youtube.com\/watch?v=YMfW1bfyGSY\">Mythbusting HTTPS: Squashing security\u2019s urban legends &#8211; Google I\/O 2016<\/a><\/p>\n<div class=\"fluid-width-video-wrapper\"><iframe loading=\"lazy\" id=\"fitvid285022\" src=\"https:\/\/www.youtube.com\/embed\/YMfW1bfyGSY\" width=\"300\" height=\"150\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<p>\u89c6\u9891\u91cc\u628a\u6240\u6709\u95ee\u9898\u90fd\u8be6\u7ec6\u4e00\u4e00\u89e3\u7b54\uff0c\u5f3a\u70c8\u63a8\u5bb6\u628a\u89c6\u9891\u770b\u5b8c\u3002<\/p>\n<p>\u6211\u7b80\u5355\u603b\u7ed3\uff1a<\/p>\n<ol>\n<li>\u6bcf\u4e2a\u7f51\u7ad9\u90fd\u5e94\u8be5\u7528 HTTPS\uff0c\u5c31\u7b97\u662f\u5168\u9759\u6001\u7ad9\u70b9\u4e5f\u540c\u6837\u5982\u6b64\uff0c\u8fd0\u8425\u5546\u52ab\u6301\u4e25\u91cd\u5e72\u6270\u8bbf\u95ee\u8005\u7684\u4f53\u9a8c<\/li>\n<li>\u6709\u51e0\u9879\u6280\u672f\u53ef\u4ee5\u63d0\u9ad8 HTTPS \u7684\u6027\u80fd\uff0c\u5305\u62ec <em>Strict Transport Security<\/em>\uff0c<em>TLS False Start<\/em> \u548c <em>HTTP\/2<\/em> \uff0c\u8fd9\u4e9b\u6280\u672f\u8ba9 HTTPS \u901f\u5ea6\u4e0d\u6162\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4f1a\u751a\u81f3\u66f4\u5feb<\/li>\n<li>HTTPS \u9488\u5bf9\u4e2a\u4eba\u5355\u4e2a\uff08\u6216\u8005\u51e0\u4e2a\uff09\u57df\u540d\u7684\u4f7f\u7528\u6765\u8bf4\uff0c\u5df2\u7ecf\u662f\u514d\u8d39\u7684<\/li>\n<li>\u914d\u7f6e\u548c\u7ef4\u62a4 HTTPS \u5f02\u5e38\u7b80\u5355\uff0c<em>Let&#8217;s Encrypt<\/em> \u8fd9\u4e2a\u9879\u76ee\u901a\u8fc7\u81ea\u52a8\u5316\u628a\u4e8b\u60c5\u7b80\u5355\u5316\u4e86<\/li>\n<\/ol>\n<h2 id=\"https\">\u6709\u54ea\u4e9b\u9760\u8c31\u7684\u514d\u8d39 HTTPS \u8bc1\u4e66\u63d0\u4f9b\u5546\uff1f<\/h2>\n<p>\u9009\u62e9\u8bc1\u4e66\u63d0\u4f9b\u5546\u67093\u4e2a\u4e3b\u8981\u8003\u91cf\uff1a1. \u6d4f\u89c8\u5668\u548c\u64cd\u4f5c\u7cfb\u7edf\u652f\u6301\u7a0b\u5ea6 2. \u8bc1\u4e66\u7c7b\u578b 3. \u7ef4\u62a4\u6210\u672c<\/p>\n<h3 id=\"1\">1. \u6d4f\u89c8\u5668\u548c\u64cd\u4f5c\u7cfb\u7edf\u652f\u6301\u7a0b\u5ea6<\/h3>\n<p>\u57fa\u672c\u4f60\u80fd\u67e5\u5230\u7684\u70ed\u95e8\u8bc1\u4e66\u63d0\u4f9b\u5546\uff0c\u652f\u6301\u7a0b\u5ea6\u90fd\u4e0d\u4f1a\u592a\u5dee\u3002\u4f8b\u5982 <em>Let&#8217;s Encrypt<\/em> \u7684\u652f\u6301\u53ef\u4ee5\u8bbf\u95ee\uff1a<a href=\"https:\/\/community.letsencrypt.org\/t\/which-browsers-and-operating-systems-support-lets-encrypt\/4394\">Which browsers and operating systems support Let\u2019s Encrypt<\/a><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cAndroid 2.3.6 \u4ee5\u4e0a\uff0cFirefox 2.0 \u4ee5\u4e0a\uff0cWindows Vista \u4ee5\u4e0a\uff0ciOS 3.1 \u4ee5\u4e0a\uff0cGoogle Chrome\u5168\u5e73\u53f0\u90fd\u662f\u652f\u6301\u7684\u3002\u8fd9\u4e00\u70b9\u5c31\u4e0d\u7528\u592a\u62c5\u5fc3\u4e86\uff0c\u770b\u4f60\u4f60\u7684\u7f51\u7ad9\u53d7\u4f17\u60c5\u51b5\u6765\u51b3\u5b9a\u3002\u5bf9\u4e8e\u6211\u6765\u8bf4\uff0c\u6211\u5b8c\u5168\u4e0d\u5728\u4e4e Windows XP \u7684 IE \u7528\u6237\u3002<\/p>\n<h3 id=\"2\">2. \u8bc1\u4e66\u7c7b\u578b<\/h3>\n<p>HTTPS \u8bc1\u4e66\u5206\u4e3a3\u7c7b\uff0c 1. DV \u57df\u540d\u9a8c\u8bc1\u8bc1\u4e66 2. OV \u7ec4\u7ec7\u673a\u6784\u9a8c\u8bc1\u8bc1\u4e66 3. EV \u589e\u5f3a\u7684\u7ec4\u7ec7\u673a\u6784\u9a8c\u8bc1\u8bc1\u4e66\u3002\u6bcf\u7c7b\u8bc1\u4e66\u5728\u5ba1\u6838\u548c\u9a8c\u8bc1\u65b9\u9762\u8981\u6c42\u4e25\u683c\u7a0b\u5ea6\u4e0d\u540c\uff0c\u6d4f\u89c8\u5668\u4f1a\u5728\u5730\u5740\u680f\u7ed9\u4e88\u4e0d\u540c\u8bc1\u4e66\u4e0d\u4e00\u6837\u7684\u5c55\u73b0\u3002<\/p>\n<p>\u4e00\u822c\u4e2a\u4eba\u4f7f\u7528DV\u8bc1\u4e66\u5b8c\u5168\u591f\u4e86\uff0c\u6d4f\u89c8\u5668\u8868\u73b0\u4e3a\u5730\u5740\u680f\u524d\u4f1a\u6709\u7eff\u8272\u7684\u5c0f\u9501\u3002\u4e0b\u9762\u804a\u5230\u7684\u514d\u8d39\u8bc1\u4e66\u90fd\u662f DV \u57df\u540d\u9a8c\u8bc1\u8bc1\u4e66\u3002<\/p>\n<h3 id=\"3\">3. \u7ef4\u62a4\u6210\u672c<\/h3>\n<p>\u6211\u8c03\u7814\u4e0d\u591a\uff0c\u4f7f\u7528\u8fc7 <em>StartSSL<\/em>\uff0c\u73b0\u5728\u7528 <em>Let&#8217;s Encrypt<\/em>\u3002<em>StartSSL<\/em> \u7684\u514d\u8d39\u8bc1\u4e66\u6709\u6548\u671f\u662f1\u5e74\uff0c1\u5e74\u540e\u9700\u8981\u624b\u52a8\u66f4\u6362\u3002\u914d\u7f6e\u8fc7\u7a0b\u8fd8\u633a\u9ebb\u70e6\u7684\u3002<\/p>\n<p>\u66f4\u63a8\u8350 <em>Let&#8217;s Encrypt<\/em>\uff0c\u867d\u7136\u6709\u6548\u671f\u53ea\u67093\u4e2a\u6708\uff0c\u4f46\u53ef\u4ee5\u7528 <a href=\"https:\/\/certbot.eff.org\/\">certbot<\/a> \u81ea\u52a8\u7eed\u671f\uff0c\u5b8c\u5168\u4e0d\u53d7\u5f71\u54cd\u3002\u800c\u4e14 <em>Let&#8217;s Encrypt<\/em> \u56e0\u4e3a\u6709\u4e86 <a href=\"https:\/\/certbot.eff.org\/\">certbot<\/a> \u8fd9\u6837\u7684\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u914d\u7f6e\u7ba1\u7406\u8d77\u6765\u975e\u5e38\u5bb9\u6613\u3002<\/p>\n<h2 id=\"letsencrypt\">\u751f\u6210 Let&#8217;s Encrypt \u8bc1\u4e66<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/zerobox.org\/notes\/wp-content\/uploads\/2016\/06\/c9821e01228e35ff3e1fe03851874db0.png\" alt=\"\" \/><\/p>\n<p><em>Let&#8217;s Encrypt<\/em> \u8bc1\u4e66\u751f\u6210\u4e0d\u9700\u8981\u624b\u52a8\u8fdb\u884c\uff0c\u5b98\u65b9\u63a8\u8350 <a href=\"https:\/\/certbot.eff.org\/\">certbot<\/a> \u8fd9\u5957\u81ea\u52a8\u5316\u5de5\u5177\u6765\u5b9e\u73b0\u30023\u6b65\u8f7b\u677e\u641e\u5b9a\uff1a<\/p>\n<ol>\n<li>\u4e0b\u8f7d\u5b89\u88c5 certbot (Let\u2019s Encrypt\u9879\u76ee\u7684\u81ea\u52a8\u5316\u5de5\u5177)<\/li>\n<li>\u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/li>\n<li>\u6267\u884c\u8bc1\u4e66\u81ea\u52a8\u5316\u751f\u6210\u547d\u4ee4<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u7684\u6559\u7a0b\u8fd0\u884c\u5728 Arch Linux \u4e0a\uff0c\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u5927\u540c\u5c0f\u5f02\u3002\u4f60\u53ef\u4ee5\u5728 <a href=\"https:\/\/certbot.eff.org\/\">certbot<\/a> \u7f51\u7ad9\u4e0a\uff0c\u9009\u62e9\u4f60\u7684 Web Server \u548c \u64cd\u4f5c\u7cfb\u7edf\uff0c\u5c31\u80fd\u770b\u5230\u5bf9\u5e94\u7684\u5b89\u88c5\u548c\u914d\u7f6e\u6559\u7a0b\u3002<\/p>\n<h3 id=\"1certbot\">1. \u4e0b\u8f7d\u5b89\u88c5 certbot<\/h3>\n<p>\u5728 Arch Linux \u4e0a\uff0c\u5b89\u88c5\u5f88\u7b80\u5355\uff1a<\/p>\n<pre><code>$ sudo pacman \uff0dSyu\r\n$ sudo pacman -S letsencrypt\r\n<\/code><\/pre>\n<h3 id=\"2\">2. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u5148\u521b\u5efa\u5b58\u653e\u914d\u7f6e\u6587\u4ef6\u7684\u6587\u4ef6\u5939\uff1a<\/p>\n<p><code>$ sudo mkdir \/etc\/letsencrypt\/configs<\/code><\/p>\n<p>\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<p><code>$ sudo vim \/etc\/letsencrypt\/configs\/example.com.conf<\/code><\/p>\n<p>\u628a example.com \u66ff\u6362\u6210\u81ea\u5df1\u7684\u57df\u540d\uff0c\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n<pre><code># \u5199\u4f60\u7684\u57df\u540d\u548c\u90ae\u7bb1\r\ndomains = example.com  \r\nrsa-key-size = 2048  \r\nemail = your-email@example.com  \r\ntext = True\r\n\r\n# \u628a\u4e0b\u9762\u7684\u8def\u5f84\u4fee\u6539\u4e3a example.com \u7684\u76ee\u5f55\u4f4d\u7f6e\r\nauthenticator = webroot  \r\nwebroot-path = \/var\/www\/example  \r\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u9700\u8981\u89e3\u91ca\u4e00\u4e0b\uff0c\u4e0a\u9762\u914d\u7f6e\u6587\u4ef6\u7528\u4e86 webroot \u7684\u9a8c\u8bc1\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5df2\u7ecf\u6709\u4e00\u4e2a Web Server \u8fd0\u884c\u4e2d\u7684\u60c5\u51b5\u3002certbot \u4f1a\u81ea\u52a8\u5728 <code>\/var\/www\/example<\/code> \u4e0b\u9762\u521b\u5efa\u4e00\u4e2a\u9690\u85cf\u6587\u4ef6 <code>.well-known\/acme-challenge<\/code> \uff0c\u901a\u8fc7\u8bf7\u6c42\u8fd9\u4e2a\u6587\u4ef6\u6765\u9a8c\u8bc1 example.com \u786e\u5b9e\u5c5e\u4e8e\u4f60\u3002\u5916\u7f51\u670d\u52a1\u5668\u8bbf\u95ee <a href=\"http:\/\/www.example.com\/.well-known\/acme-challenge\">http:\/\/www.example.com\/.well-known\/acme-challenge<\/a> \uff0c\u5982\u679c\u8bbf\u95ee\u6210\u529f\u5219\u9a8c\u8bc1OK\u3002<\/p>\n<p>\u6211\u4eec\u4e0d\u9700\u8981\u624b\u52a8\u521b\u5efa\u8fd9\u4e2a\u6587\u4ef6\uff0ccertbot \u4f1a\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u81ea\u52a8\u5b8c\u6210\u3002<\/p>\n<h3 id=\"3\">3. \u6267\u884c\u8bc1\u4e66\u81ea\u52a8\u5316\u751f\u6210\u547d\u4ee4<\/h3>\n<p>\u4e00\u5207\u5c31\u7eea\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u8fd0\u884c certbot \u4e86\u3002\uff08\u6ce8\u610f\uff1acertbot \u5176\u5b9e\u662f\u4e00\u4e2a Python \u811a\u672c\uff0c\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u7684\u547d\u4ee4\u4f1a\u4e0d\u540c\uff0c\u4f8b\u5982\u5728 Arch Linux \u4e0a certbot \u7684\u547d\u4ee4\u662f letsencrypt\uff09\u3002<\/p>\n<pre><code>$ sudo letsencrypt -c \/etc\/letsencrypt\/configs\/example.com.conf certonly\r\n\r\n## \u7247\u523b\u4e4b\u540e\uff0c\u770b\u5230\u4e0b\u9762\u5185\u5bb9\u5c31\u662f\u6210\u529f\u4e86\r\nIMPORTANT NOTES:  \r\n - Congratulations! Your certificate and chain have been saved at \/etc\/letsencrypt\/live\/example.com\/fullchain.pem.\r\n<\/code><\/pre>\n<p>\u5982\u679c\u8fd0\u884c\u987a\u5229\uff0c\u6240\u6709\u670d\u52a1\u5668\u6240\u9700\u8981\u7684\u8bc1\u4e66\u5c31\u5df2\u7ecf\u751f\u6210\u597d\u4e86\u3002\u4ed6\u4eec\u88ab\u653e\u5728\u4e86 <code>\/etc\/letsencrypt\/live\/example.com\/<\/code> \u4e0b\uff1a<\/p>\n<pre><code>$ ls \/etc\/letsencrypt\/live\/example.com\/\r\ncert.pem #server cert only  \r\nprivkey.pem #private key  \r\nchain.pem #intermediates  \r\nfullchain.pem #server cert + intermediates  \r\n<\/code><\/pre>\n<h2 id=\"nginx\">\u914d\u7f6e Nginx \u52a0\u5165\u8bc1\u4e66<\/h2>\n<p>\u5230\u8fd9\u91cc\u5df2\u7ecf\u6210\u529f\u4e00\u5927\u534a\u4e86\uff0c\u53ea\u9700\u8981\u914d\u7f6e Nginx \u652f\u6301\u521a\u521a\u751f\u6210\u7684\u8bc1\u4e66\u3002\u800c\u4e14\u8fd9\u4e2a\u914d\u7f6e\u6709\u6700\u4f73\u5b9e\u8df5\u53ef\u4ee5\u53c2\u8003\uff0c\u8bbf\u95ee\uff1a<a href=\"https:\/\/mozilla.github.io\/server-side-tls\/ssl-config-generator\/\">Mozilla SSL Configuration Generator<\/a>\uff0c\u8fd9\u662f Mozilla \u641e\u5f97\u4e00\u4e2a HTTPS \u914d\u7f6e\u6587\u4ef6\u81ea\u52a8\u751f\u6210\u5668\uff0c\u652f\u6301 Apache\uff0cNginx \u7b49\u591a\u79cd\u670d\u52a1\u5668\u3002\u6309\u7167\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u9009\u62e9 <strong>Intermediate<\/strong> \u7684\u517c\u5bb9\u6027\u3002\u8fd9\u91cc\u751f\u6210\u7684\u914d\u7f6e\u6587\u4ef6\u662f\u4e1a\u754c\u6700\u4f73\u5b9e\u8df5\u548c\u7ed3\u679c\uff0c\u8ba9 Nginx \u6253\u5f00\u4e86\u5404\u79cd\u589e\u52a0\u5b89\u5168\u6027\u548c\u6027\u80fd\u7684\u53c2\u6570\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/zerobox.org\/notes\/wp-content\/uploads\/2016\/06\/e4b4a925f1d3cd44ad14afad3d2762f3.png\" alt=\"\" \/><\/p>\n<p>\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code>server {  \r\n    listen 80 default_server;\r\n    listen [::]:80 default_server;\r\n\r\n    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.\r\n    return 301 https:\/\/$host$request_uri;\r\n}\r\n\r\nserver {  \r\n    listen 443 ssl http2;\r\n    listen [::]:443 ssl http2;\r\n\r\n    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate\r\n    ssl_certificate \/path\/to\/signed_cert_plus_intermediates;\r\n    ssl_certificate_key \/path\/to\/private_key;\r\n    ssl_session_timeout 1d;\r\n    ssl_session_cache shared:SSL:50m;\r\n    ssl_session_tickets off;\r\n\r\n    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits\r\n    ssl_dhparam \/path\/to\/dhparam.pem;\r\n\r\n    # intermediate configuration. tweak to your needs.\r\n    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\r\n    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';\r\n    ssl_prefer_server_ciphers on;\r\n\r\n    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)\r\n    add_header Strict-Transport-Security max-age=15768000;\r\n\r\n    # OCSP Stapling ---\r\n    # fetch OCSP records from URL in ssl_certificate and cache them\r\n    ssl_stapling on;\r\n    ssl_stapling_verify on;\r\n\r\n    ## verify chain of trust of OCSP response using Root CA and Intermediate certs\r\n    ssl_trusted_certificate \/path\/to\/root_CA_cert_plus_intermediates;\r\n\r\n    resolver &lt;IP DNS resolver&gt;;\r\n\r\n    ....\r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u6839\u636e\u81ea\u5df1\u7684\u670d\u52a1\u914d\u7f6e\u4fee\u6539\u548c\u6dfb\u52a0\u5185\u5bb9\uff0c\u91cd\u70b9\u53ea\u9700\u8981\u5173\u6ce86\u884c\uff1a<\/p>\n<pre><code>server {  \r\n    listen 443 ssl http2;\r\n    ....\r\n    ssl_certificate \/etc\/letsencrypt\/live\/example.com\/fullchain.pem;\r\n    ssl_certificate_key \/etc\/letsencrypt\/live\/example.com\/privkey.pem;\r\n    ssl_dhparam \/etc\/nginx\/ssl\/dhparam.pem;\r\n\r\n    ssl_trusted_certificate \/etc\/letsencrypt\/live\/example.com\/root_ca_cert_plus_intermediates;\r\n\r\n    resolver &lt;IP DNS resolver&gt;;\r\n    ....\r\n}\r\n<\/code><\/pre>\n<p>\u8fd96\u884c\u4e2d\uff0c\u90e8\u5206\u6587\u4ef6\u8fd8\u4e0d\u5b58\u5728\uff0c\u9010\u4e2a\u8bf4\u660e\u3002<\/p>\n<p>\u9996\u5148\u662f\u7b2c\u4e00\u884c <code>listen 443 ssl http2;\u00a0<\/code> \u4f5c\u7528\u662f\u542f\u7528 Nginx \u7684 <a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_v2_module.html\">ngx<em>http<\/em>v2_module \u6a21\u5757<\/a> \u652f\u6301 HTTP2\uff0cNginx \u7248\u672c\u9700\u8981\u9ad8\u4e8e 1.9.5\uff0c\u4e14\u7f16\u8bd1\u65f6\u9700\u8981\u8bbe\u7f6e <code>--with-http_v2_module<\/code> \u3002Arch Linux \u7684 Nginx \u5b89\u88c5\u5305\u4e2d\u5df2\u7ecf\u7f16\u8bd1\u4e86\u8fd9\u4e2a\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u3002\u5982\u679c\u4f60\u7684 Linux \u53d1\u884c\u7248\u672c\u4e2d\u7684 Nginx \u5e76\u4e0d\u652f\u6301\u8fd9\u4e2a\u6a21\u5757\uff0c\u53ef\u4ee5\u81ea\u884c Google \u5982\u4f55\u52a0\u4e0a\u3002<\/p>\n<p><code>ssl_certificate<\/code> \u548c <code>ssl_certificate_key<\/code> \uff0c\u5206\u522b\u5bf9\u5e94 <code>fullchain.pem<\/code> \u548c <code>privkey.pem<\/code>\uff0c\u8fd92\u4e2a\u6587\u4ef6\u662f\u4e4b\u524d\u5c31\u751f\u6210\u597d\u7684\u8bc1\u4e66\u548c\u5bc6\u94a5\u3002<\/p>\n<p><code>ssl_dhparam<\/code> \u901a\u8fc7\u4e0b\u9762\u547d\u4ee4\u751f\u6210\uff1a<\/p>\n<pre><code>$ sudo mkdir \/etc\/nginx\/ssl\r\n$ sudo openssl dhparam -out \/etc\/nginx\/ssl\/dhparam.pem 2048\r\n<\/code><\/pre>\n<p>\uff08\u53ef\u9009\uff09<code>ssl_trusted_certificate<\/code> \u9700\u8981\u4e0b\u8f7d <em>Let&#8217;s Encrypt<\/em> \u7684 <a href=\"https:\/\/letsencrypt.org\/certificates\/\">Root Certificates<\/a>\uff0c\u4e0d\u8fc7\u6839\u636e<a href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_ssl_module.html#ssl_stapling\">Nginx \u5b98\u65b9\u6587\u6863<\/a> \u6240\u8bf4\uff0c<code>ssl_certificate<\/code> \u5982\u679c\u5df2\u7ecf\u5305\u542b\u4e86 <code>intermediates<\/code> \u5c31\u4e0d\u518d\u9700\u8981\u63d0\u4f9b ssl<em>trusted<\/em>certificate \u4e86\u3002\u8fd9\u4e00\u6b65\u53ef\u4ee5\u7701\u7565\uff1a<\/p>\n<pre><code>$ cd \/etc\/letsencrypt\/live\/example.com\r\n$ sudo wget https:\/\/letsencrypt.org\/certs\/isrgrootx1.pem\r\n$ sudo mv isrgrootx1.pem root.pem\r\n$ sudo cat root.pem chain.pem &gt; root_ca_cert_plus_intermediates\r\n<\/code><\/pre>\n<p><code>resolver<\/code> \u7684\u4f5c\u7528\u662f \u201cresolve names of upstream servers into addresses\u201d\uff0c \u5728\u9019\u500b\u914d\u7f6e\u4e2d\uff0cresolver \u662f\u7528\u4f86\u89e3\u6790 OCSP \u670d\u52d9\u5668\u7684\u57df\u540d\u7684\uff0c\u5efa\u8bae\u586b\u5199\u4f60\u7684 VPS \u63d0\u4f9b\u5546\u7684 DNS \u670d\u52a1\u5668\uff0c\u4f8b\u5982\u6211\u7684 VPN \u5728 Linode\uff0cDNS\u670d\u52a1\u5668\u586b\u5199\uff1a<\/p>\n<p><code>resolver 106.187.90.5 106.187.93.5;<\/code><\/p>\n<p>Nginx \u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u91cd\u542f\u540e\uff0c\u7528\u6d4f\u89c8\u5668\u6d4b\u8bd5\u662f\u5426\u4e00\u5207\u6b63\u5e38\u3002<\/p>\n<pre><code>$ sudo systemctl restart nginx\r\n<\/code><\/pre>\n<p>\u8fd9\u65f6\u5019\u4f60\u7684\u7ad9\u70b9\u5e94\u8be5\u9ed8\u8ba4\u5f3a\u5236\u4f7f\u7528\u4e86 HTTPS\uff0c\u5e76\u4e14\u6d4f\u89c8\u5668\u5730\u5740\u680f\u5de6\u8fb9\u4f1a\u6709\u7eff\u8272\u7684\u5c0f\u9501\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/zerobox.org\/notes\/wp-content\/uploads\/2016\/06\/721b0ed2756eaf03d45d0a645bbea9f7.png\" alt=\"\" \/><\/p>\n<h2 id=\"\">\u81ea\u52a8\u5316\u5b9a\u671f\u66f4\u65b0\u8bc1\u4e66<\/h2>\n<p><em>Let&#8217;s Encrypt<\/em> \u8bc1\u4e66\u6709\u6548\u671f\u662f3\u4e2a\u6708\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 certbot \u6765\u81ea\u52a8\u5316\u7eed\u671f\u3002<\/p>\n<p>\u5728 Arch Linux \u4e0a\uff0c\u6211\u4eec\u901a\u8fc7 systemd \u6765\u81ea\u52a8\u6267\u884c\u8bc1\u4e66\u7eed\u671f\u4efb\u52a1\u3002<\/p>\n<pre><code>$ sudo vim \/etc\/systemd\/system\/letsencrypt.service\r\n<\/code><\/pre>\n<pre><code>[Unit]\r\nDescription=Let's Encrypt renewal\r\n\r\n[Service]\r\nType=oneshot  \r\nExecStart=\/usr\/bin\/letsencrypt renew  \r\nExecStartPost=\/bin\/systemctl reload nginx.service  \r\n<\/code><\/pre>\n<p>\u7136\u540e\u589e\u52a0\u4e00\u4e2a systemd timer \u6765\u89e6\u53d1\u8fd9\u4e2a\u670d\u52a1\uff1a<\/p>\n<pre><code>$ sudo vim \/etc\/systemd\/system\/letsencrypt.timer\r\n<\/code><\/pre>\n<pre><code>[Unit]\r\nDescription=Monthly renewal of Let's Encrypt's certificates\r\n\r\n[Timer]\r\nOnCalendar=daily  \r\nPersistent=true\r\n\r\n[Install]\r\nWantedBy=timers.target  \r\n<\/code><\/pre>\n<p>\u542f\u7528\u670d\u52a1\uff0c\u5f00\u542f timer\uff1a<\/p>\n<pre><code>$ sudo systemctl enable letsencrypt.service\r\n$ sudo systemctl start letsencrypt.timer\r\n<\/code><\/pre>\n<p>\u5728\u5176\u4ed6 Linux \u53d1\u884c\u7248\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 crontab \u6765\u8bbe\u5b9a\u5b9a\u65f6\u4efb\u52a1\uff0c\u81ea\u884c Google \u5427\u3002<\/p>\n<h2 id=\"ssl\">\u7528\u4e13\u4e1a\u5728\u7ebf\u5de5\u5177\u6d4b\u8bd5\u4f60\u7684\u670d\u52a1\u5668 SSL \u5b89\u5168\u6027<\/h2>\n<p><a href=\"https:\/\/www.ssllabs.com\/ssltest\/index.html\">Qualys SSL Labs<\/a> \u63d0\u4f9b\u4e86\u5168\u9762\u7684 SSL \u5b89\u5168\u6027\u6d4b\u8bd5\uff0c\u586b\u5199\u4f60\u7684\u7f51\u7ad9\u57df\u540d\uff0c\u7ed9\u81ea\u5df1\u7684 HTTPS \u914d\u7f6e\u6253\u4e2a\u5206\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5b8c\u5168\u6309\u7167\u6211\u4e0a\u9762\u6559\u7a0b\u914d\u7f6e\uff0c\u9075\u5faa\u4e86\u6700\u4f73\u5b9e\u8df5\uff0c<a href=\"https:\/\/www.ssllabs.com\/ssltest\/analyze.html?d=ksmx.me&amp;latest\">\u4f60\u5e94\u8be5\u548c\u6211\u4e00\u6837\u5f97\u5206\u662f A+<\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/zerobox.org\/notes\/wp-content\/uploads\/2016\/06\/428f6e00cc7ea0f5eed4fd09581931e2.png\" alt=\"\" \/><\/p>\n<p>\u8fd9\u610f\u5473\u7740\u4f60\u542f\u7528\u4e86HTTPS\uff0c\u73b0\u5728\u8db3\u591f\u7684\u5b89\u5168\uff0c\u5e76\u4e14\u4f7f\u7528\u4e86\u6700\u65b0\u6280\u672f\uff0c\u4fdd\u8bc1\u4e86\u6027\u80fd\u3002<\/p>\n<p>\u4e3a\u81ea\u5df1\u9f13\u4e2a\u638c\u3002 (\u0e51\u2022\u0300\u3142\u2022\u0301)\u0648\u2727<\/p>\n<\/section>\n<footer class=\"post-footer\">\n<figure class=\"author-image\"><\/figure>\n<section class=\"author\">\n<h4><a href=\"https:\/\/ksmx.me\/author\/michael\/\">\u5eb7\u4e0a\u660e\u5b66<\/a><\/h4>\n<p>\u7406\u60f3\u4e3b\u4e49\u8005\uff0c\u60f3\u5f97\u592a\u591a\uff0c\u505a\u5f97\u592a\u5c11\u3002\u6b22\u8fce\u5173\u6ce8\u5fae\u4fe1\u516c\u5171\u53f7\u300c\u660e\u5b66\u7684\u767d\u677f\u300d<\/p>\n<div class=\"author-meta\"><span class=\"author-location icon-location\">Beijing<\/span> <span class=\"author-link icon-link\"><a href=\"http:\/\/ksmx.me\/\">http:\/\/ksmx.me<\/a><\/span><\/div>\n<\/section>\n<\/footer>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u6bb5\u65f6\u95f4\u5728\u5317\u4eac\u8054\u901a3G\u79fb\u52a8\u7f51\u7edc\u4e0b\uff0c\u53d1\u73b0\u81ea\u5df1\u7684\u7ad9\u70b9\u88ab\u8054\u901a\u52ab\u6301\u6ce8\u5165\u6076\u5fc3\u7684\u8bdd\u8d39\u5145\u503c\u5e7f\u544a &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/1096.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1097,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[242],"class_list":["post-1096","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-lets-encrypt"],"views":4059,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/1096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=1096"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/1096\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media\/1097"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=1096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=1096"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=1096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}