怎样在Node.Js中启用HTTP/2.0?
发布时间:09/01 来源:未知 浏览:
关键词:
安置Node.Js
假如已经在系统上安置了node.js,则可以跳过此步骤。假如系统上没有node.js,请使用以下命令安置。
$ sudo apt-get install python-software-properties python g++ make $ curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - $ sudo apt-get update $ sudo apt-get install nodejs
当然也可以通过NPM升级node.js。
安置Node-HTTP2模块
node-http2模块在默许的npm库下可用。因此,只需施行以下命令即可为利用程序安置它。
$ npm install http2
创立node效劳器
让我们创立一个支撑HTTP/2的示例节点效劳器。第一创立自定义的SSL证书或从授权的SSL供给程序猎取有效的SSL。
$ openssl req -x509 -nodes -newkey rsa:2048 -keyout example.com.key -out example.com.crt
此刻创立包括以下内容的http2-server.js文件。
var fs = require('fs'); var options = { key: fs.readFileSync('./example.com.key'), cert: fs.readFileSync('./example.com.crt') }; require('http2').createServer(options, function(request, response) { response.end('Welcome HTTP/2.0'); console.log("Server listening on: http://localhost:8000"); }).listen(8000);
启动node效劳器
让我们使用以下命令启动node.js效劳器。它将在系统的端口8000上启动Web效劳器。
$ node http2-server.js
并在端口8000上拜访localhost。
本篇文章到这里就已经全部完毕了,更多其他出色内容可以关注PHP中文网的node.js教程视频栏目!
以上就是怎样在Node.Js中启用HTTP/2.0?的具体内容,更多请关注百分百源码网其它相关文章!