{"id":5814,"date":"2017-07-11T18:29:14","date_gmt":"2017-07-11T10:29:14","guid":{"rendered":"https:\/\/sdeno.com\/?p=5814"},"modified":"2017-07-12T18:15:46","modified_gmt":"2017-07-12T10:15:46","slug":"node-js%e9%85%8d%e7%bd%aessl%e3%80%81http2","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5814","title":{"rendered":"node.js\u914d\u7f6essl\u3001http2"},"content":{"rendered":"<p>koa2\u5f00\u542fssl\u5b89\u5168\u534f\u8bae\u3001\u4ee5\u53ca\u914d\u7f6ehttp2\uff0c\u6240\u4ee5\u6559\u7a0b\u90fd\u662f\u57fa\u4e8ekoa2\u6846\u67b6\u4e0b\u4fee\u6539\u7684\u3002<\/p>\n<p>\u8fd9\u91cc\u8bf4\u660e\u4e00\u4e0b\uff0c\u7f51\u4e0a\u7684\u5f88\u591a\u6559\u7a0b\u90fd\u662f\u4f7f\u7528nginx\u6765\u8fdb\u884c\u914d\u7f6e\u7684\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u4e0d\u719f\u6089linux\u7cfb\u7edf\u7684\u540c\u5b66\u6765\u8bf4\u5f88\u75db\u82e6\u3002\u8fd9\u91cc\u7684\u6559\u7a0b\u57fa\u672c\u90fd\u662f\u5b89\u88c5node.js\u6a21\u5757\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u7533\u8bf7\u8bc1\u4e66\uff1a<a href=\"https:\/\/cloud.tencent.com\/product\/ssl?fromSource=gwzcw.231572.231572.231572\" target=\"_blank\">https:\/\/cloud.tencent.com\/product\/ssl?fromSource=gwzcw.231572.231572.231572<\/a><\/p>\n<p>\u7533\u8bf7\u597d\u4e4b\u540e\u5c31\u53ef\u4ee5\u4e0b\u8f7d\u4e86\u3002<\/p>\n<p>\uff08\u6ce8\u610f\u5982\u679c\u5728\u56fd\u5185\u4e70\u7684\u7a7a\u95f4\uff0c\u4f8b\u5982\uff1a\u963f\u91cc\u4e91\u7684\u8bb0\u5f97\u8981\u5bf9\u5916\u5f00\u653e443\u7aef\u53e3\uff09\u6559\u7a0b\uff1a<a href=\"https:\/\/sdeno.com\/?p=5797\" target=\"_blank\">https:\/\/sdeno.com\/?p=5797<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>0\uff0c<span style=\"color: #ff0000;\">\u7cfb\u7edf\u4f9d\u8d56<\/span><\/p>\n<p>\u672c\u4eba\u4f7f\u7528\u7684\u662fcentos 6.x\u7cfb\u7edf\uff0c\u8981\u4f7f\u7528ssl\u3001http2\uff0c\u90a3\u5c31\u9700\u8981\u7cfb\u7edf\u5b89\u88c5\u76f8\u5e94\u7684\u4f9d\u8d56\u5305\u3002<\/p>\n<p>\u5177\u4f53\u67e5\u770b<a href=\"https:\/\/sdeno.com\/?p=5731\" target=\"_blank\">https:\/\/sdeno.com\/?p=5731<\/a>\u00a0\u4e2d\u7684\u00a0gcc\u3001pcre\u3001zlib\u548copenssl 1.0.2\u4ee5\u4e0a\u7248\u672c<\/p>\n<p>&nbsp;<\/p>\n<p>1\uff0c<span style=\"color: #ff0000;\">http2\u3001ssl\u5b89\u88c5\u3001\u4ee5\u53ca\u4f7f\u7528<\/span><\/p>\n<pre>npm install http2 --save\r\n\r\n\u7f16\u8f91  .\/bin\/www  \u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\r\n\r\nvar http2 = require('http2');\r\nvar fs = require('fs');\r\n.\r\n.\r\n.\r\nvar options = {\r\n key: fs.readFileSync('\/root\/www\/Nginx\/2_www.easynode.cn.key','utf8'),\r\n cert: fs.readFileSync('\/root\/www\/Nginx\/1_www.easynode.cn_bundle.crt','utf8')\r\n};\r\n.\r\n.\r\n.\r\nhttp2.createServer(options, app.callback()).listen(443);\r\n<\/pre>\n<p>\u4ee5\u4e0a\u7684\u914d\u7f6e\u5b8c\u6210\u540e\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee80\u7aef\u53e3\u548c443\u7aef\u53e3\uff0c\u4f46\u662f\u6211\u4eec\u9700\u8981\u81ea\u52a8\u8df3\u8f6c\u5230443\u7aef\u53e3\uff0c\u53ef\u6309\u7167\u5982\u4e0b\u6559\u7a0b\u4fee\u6539\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>2\uff0c<span style=\"color: #ff0000;\">80\u7aef\u53e3\u81ea\u52a8\u8df3\u8f6c\u5230443\u7aef\u53e3<\/span><\/p>\n<p>\u5b89\u88c5koa-sslify<\/p>\n<pre>npm install koa-sslify --save\r\n\r\n\u7f16\u8f91app.js,\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\r\nvar enforceHttps = require('koa-sslify');\r\n.\r\n.\r\n\/\/ middlewares\r\napp.use(enforceHttps());<\/pre>\n<p>\u4ee5\u4e0a\u867d\u7136\u53ef\u4ee5\u5b9e\u73b0\u9700\u8981\u7684\u529f\u80fd\u4f46\u662f\u6709\u7f3a\u70b9<\/p>\n<p>1\uff0c\u5bf9\u9759\u6001\u6587\u4ef6\u7f13\u5b58\uff08\u7f51\u4e0a\u627e\u904d\u4e86\u5f88\u591a\u6559\u7a0b\u90fd\u6ca1\u627e\u5230\u65b9\u6cd5\uff0c\u90fd\u662f\u4f7f\u7528nginx\uff09<\/p>\n<p>2\uff0c\u5360\u7528\u4e86443\u7aef\u53e3\u3002\uff08\u5982\u679c\u4e00\u4e2a\u670d\u52a1\u5668\u4e0a\u60f3\u591a\u4e2a\u7f51\u7ad9\u90fd\u4f7f\u7528ssl\uff0c\u5c31\u53ea\u80fd\u4f7f\u7528\u4e00\u4e2a\u7aef\u53e3\u4e86\uff09<\/p>\n<p>\u6240\u4ee5\u8fd8\u662f\u63a8\u8350\u4f7f\u7528nginx\uff0c\u6765\u5b9e\u73b0ssl\u3001http2\u548c\u9759\u6001\u6587\u4ef6\u7f13\u5b58\uff0c\u6700\u4f73\u65b9\u6848\u3002<\/p>\n<p>\u81f3\u4e8enginx\u6559\u7a0b\uff1a<a href=\"https:\/\/sdeno.com\/?p=5731\" target=\"_blank\">https:\/\/sdeno.com\/?p=5731<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>koa2\u5f00\u542fssl\u5b89\u5168\u534f\u8bae\u3001\u4ee5\u53ca\u914d\u7f6ehttp2\uff0c\u6240\u4ee5\u6559\u7a0b\u90fd\u662f\u57fa\u4e8ekoa2\u6846\u67b6\u4e0b\u4fee\u6539\u7684\u3002 \u8fd9\u91cc\u8bf4\u660e\u4e00\u4e0b\uff0c\u7f51\u4e0a\u7684\u5f88 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[],"class_list":["post-5814","post","type-post","status-publish","format-standard","hentry","category-koa"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5814"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5814\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}