我有一个完整的生产服务器,具有以下设置: 在端口3000上使用Nginx和SSL配置的NodeJS。ExpressJS作为前端。与A服务器(ExpressJS + Nodejs + Nginx + SSL)的套接字连接问题
现在我想添加一些套接字工作里面。 我创建了一个名为使用下面的代码server.js新文件:
var net = require('net');
var HOST = '127.0.0.1';
var PORT = 6969;
net.createServer(function(sock) {
// We have a connection - a socket object is assigned to the connection automatically
console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);
// Add a 'data' event handler to this instance of socket
sock.on('data', function(data) {
console.log('DATA ' + sock.remoteAddress + ': ' + data);
// Write the data back to the socket, the client will receive it as data from the server
sock.write('You said "' + data + '"');
});
// Add a 'close' event handler to this instance of socket
sock.on('close', function(data) {
console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
});
sock.on('error', function(err) {
console.log(err)
})
}).listen(PORT, HOST);
console.log('Server listening on ' + HOST +':'+ PORT);
我已经加入我的主要app.js文件这一行:
require('./app/server');
现在,当我启动服务器时,它打印效果与预期行: “套接字服务器监听127.0.0.1:6969” 和
“生产的NodeJS服务器上的3000端口监听”现在,当我尝试到达插座服务器:
netcat [destination] 6969
它不起作用。 但是,当我在没有SSL和Nginx的本地主机开发服务器上尝试它时,它确实有效。
也许我不得不添加一些Nginx配置或安全连接来查看套接字,但我无法在线找到任何线索。
请任何帮助,将不胜感激!