Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将Apache Tomcat SSL证书与节点js https和websickets一起使用_Javascript_Node.js_Ssl_Tomcat_Https - Fatal编程技术网

Javascript 如何将Apache Tomcat SSL证书与节点js https和websickets一起使用

Javascript 如何将Apache Tomcat SSL证书与节点js https和websickets一起使用,javascript,node.js,ssl,tomcat,https,Javascript,Node.js,Ssl,Tomcat,Https,我犯了一个错误 WebSocket connection to 'wss://example.com:5152/' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR 当我尝试从我们的网站访问websocket时,使用我的Nodejs web套接字。网站和websocket位于同一台服务器上不同的端口,在本地主机和主机上一切正常 ws://example.com:5152 我们的网站已经有一个CA证书,

我犯了一个错误

WebSocket connection to 'wss://example.com:5152/' failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR
当我尝试从我们的网站访问websocket时,使用我的Nodejs web套接字。网站和websocket位于同一台服务器上不同的端口,在本地主机和主机上一切正常

ws://example.com:5152
我们的网站已经有一个CA证书,我想使用同样的websocket

目前这是我的代码

var cfg = {
  ssl: true,
  port: 5152,
  //ssl_key:'/usr/java/tomcat/ssl/gdig2.crt.pem',
  ssl_key: 'certificates/key.pem',
  ssl_cert: 'certificates/cert.pem'
};

var httpServ = (cfg.ssl) ? require('https') : require('http');

var WebSocketServer = require('ws').Server;

var app = null;

// dummy request processing
var processRequest = function (req, res) {
  res.writeHead(200);
  res.end("Server runs!\n");
};

app = cfg.ssl ?
  httpServ.createServer({
    key: fs.readFileSync(cfg.ssl_key),
    cert: fs.readFileSync(cfg.ssl_cert)
  }, processRequest).listen(cfg.port) :
  httpServ.createServer(processRequest).listen(cfg.port)

// passing or reference to web server so WS would knew port and SSL capabilities
const wss = new WebSocketServer({ server: app });

wss.on('connection', (client) => {
  console.log("Client connected")
}
有些代码很明显是错误的,但这很好用。。我只想知道如何更换:

key: fs.readFileSync(cfg.ssl_key),
cert: fs.readFileSync(cfg.ssl_cert)
使用tomcat SSl密钥

如果这个问题没有说清楚,请指出,我会进一步解释

提前感谢救世主。。。哈哈