腾讯云Windows Server下nodejs websocket ssl配置
1.从腾讯云申请SSL证书,下载解压,得到如下文件:
2.nodejs代码:
// wss.js const fs = require('fs'); // 一些配置信息
const cfg = {
port: 8888,
ssl_key: 'ssl.key', //这里填Apache中的 3_[域名].key 文件
ssl_cert: 'ssl.crt', //这里填Apache中的 2_[域名].crt 文件
ssl_ca:'root_bundle.crt' //这里填Apache中的 1_root_bundle.crt文件
}; const httpServ = require('https');
const WebSocketServer = require('ws').Server; // 引用Server类 // 创建request请求监听器
const processRequest = (req, res) => {
res.writeHead(200);
res.end('厉害了,我的WebSockets!\n');
}; const app = httpServ.createServer({
// 向server传递key和cert参数
key: fs.readFileSync(cfg.ssl_key),
cert: fs.readFileSync(cfg.ssl_cert),
ca: fs.readFileSync(cfg.ssl_ca)
}, processRequest).listen(cfg.port); // 实例化WebSocket服务器
const wss = new WebSocketServer({
server: app
});
// 如果有WebSocket请求接入,wss对象可以响应connection事件来处理
wss.on('connection', (wsConnect) => {
console.log('服务器已启动,监听中~');
wsConnect.on('message', (message) => {
console.log(`服务器接收到:${message}`);
wsConnect.send(`服务器回复: ${message}`, (err) => {
if (err) {
console.log(`服务器错误:${err}`);
}
});
});
});
参考:
https://blog.csdn.net/u013052238/article/details/81234898
https://blog.csdn.net/chaoshengze/article/details/78406039?locationNum=5&fps=1
腾讯云Windows Server下nodejs websocket ssl配置的更多相关文章
- Windows系统下nodejs安装及配置
关于nodejs中文站,眼下活跃度最好的知识站应该是http://www.cnodejs.org/ ,而http://cnodejs.org/则活跃度较低.Express.js是nodejs的一个MV ...
- 阿里云windows server 2012 TIME_WAIT CLOSE_WAIT
新申请的阿里云windows server 2012 R2上部署安装了socket服务器,但客户端连接后老是断开(心跳包没有),服务假死(服务不断也走),客户端申请连接会也会死在cmd下输入指令 ne ...
- mysql 在windows server下发生系统错误 1067, 进程意外终止的解决方法
mysql 在windows server下发生系统错误 1067, 进程意外终止,请检查系统盘下的windows目录下是否存在mysql的配置文件my.ini,如存在,将其删除或改名即可.
- GITHUB个人博客搭建-Pelican 在Windows环境下的安装及配置
GITHUB个人博客搭建-Pelican 在Windows环境下的安装及配置 前言 此篇博客主要为Pelican在Windows平台下的配置安装所写,在此过程中主要参考资料烟雨林博客.poem_of_ ...
- Windows Server实例防火墙策略的配置方法
概述 本文介绍在Windows Server实例中,如何配置防火墙策略的方法. 详细描述 配置Windows Server版本的防火墙功能方法,参考如下步骤. 提示:此处以Windows Server ...
- windows server 2012 R2里IIS配置.net core2.1遇到的坑
首先刚接触.net core不久,在本地也是简单写点测试程序,没遇到过什么问题,感觉还行,最近朋友搞了个asp.net core2.1的程序,让我给他服务器配置一下,我想这都跨平台了有什么难的吗?拿来 ...
- Windows Server 2008 DNS服务器安装与配置
Windows Server 2008 DNS服务器安装与配置本文关键字:Windows Server 2008 DNS.IIS 服务器安装与配置,DNS服务器本文来源:http://www.ip-t ...
- Linux环境下NodeJS的安装配置(HelloWorld)
Linux环境下NodeJS的安装配置(HelloWorld) 最简单的环境安装,测试helloworld.给初学者!! 安装脚本,请仔细阅读逐行执行: #!/bin/bash #检查是否已经安装 r ...
- Windows Server 2019远程桌面服务配置和授权激活
参考Windows Server 2016远程桌面服务配置和授权激活方法可适用于Windows Server 2019 Server 2016默认远程桌面连接数是2个用户,如果多余两个用户进行 ...
随机推荐
- python3练习100题——012
今天继续,答案都通过py3测试. 原题链接:http://www.runoob.com/python/python-exercise-example12.html 题目:判断101-200之间有多少个 ...
- 【转载】Hive vs HBase
转自:http://www.chinastor.com/a/hbase/0G3Z532014.html Hive是什么? Apache Hive是一个构建于Hadoop(分布式系统基础架构)顶层的数据 ...
- slice 实现原理
package main /* #include <stdlib.h> */ import "C" import ( "unsafe" " ...
- argmax( )
argmax是一种函数,是对函数求参数(集合)的函数. 当我们有另一个函数y=f(x)时,若有结果x0= argmax(f(x)),则表示当函数f(x)取x=x0的时候,得到f(x)取值范围的最大值: ...
- pytorch怎么入门学习
pytorch怎么入门学习 https://www.zhihu.com/question/55720139
- FastDFS :java.lang.Exception: getStoreStorage fail, errno code: 28
FastDFS 服务正常,突然报错:java.lang.Exception: getStoreStorage fail, errno code: 28 答:错误代码28表示 No space left ...
- CF1288F Red-Blue Graph
Link 考虑上下界+费用流. 对于左部点\(u\): 如果颜色为\(B\),连\((s,u,[1,+\infty),0)\). 如果颜色为\(R\),连\((u,t,[1,+\infty),0)\) ...
- 【C语言】用C语言输出一个吃豆人
大圆盘减去扇形和小圆盘: #include <math.h> #include <stdio.h> int main() { double x, y; ; y >= -; ...
- 静态方法使用synchronized修饰.
package seday10;/** * @author xingsir * 静态方法若使用synchronized修饰,这个方法一定具有同步效果.静态方法上使用的同步监视器对象为这个类的" ...
- Bugku-CTF之前女友(SKCTF)
Day35 前女友(SKCTF) http://123.206.31.85:49162/ flag格式:SKCTF{xxxxxxxxxxxxxxxxxx}