NodeJs 无法侦听数字海洋 Ubuntu 上的端口


NodeJs not able to listen to port on digital ocean Ubuntu

我正在尝试在我的服务器上实现消息传递。这是 Ubuntu 14.04/Nginx

我已经安装了

1.nodejs 
2.Redis
3.laravel 

全部成功

当我运行命令时

node -v

它给了我节点的版本

在我的控制器中,我的代码如下所示

public function sendMessage(){
        $redis = LRedis::connection();
        $redis->publish('message', 'Sending Message to Port');
        return redirect('writemessage');
    }

我的服务器.js代码是这样的

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');
server.listen(8890);
io.on('connection', function (socket) {
  console.log("new client connected");
  var redisClient = redis.createClient();
  redisClient.subscribe('message');
  redisClient.on("message", function(channel, message) {
    console.log("mew message in queue "+ message + "channel");
    socket.emit(channel, message);
  });
  socket.on('disconnect', function() {
    redisClient.quit();
  });
});

Redis 服务器在默认 6379 上运行

并收听广播我的套接字.php文件具有以下代码

<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://cdn.socket.io/socket.io-1.3.4.js"></script>
    <script>
        var socket = io.connect('http://localhost:8890');
        socket.on('message', function (data) {
            $( "#messages" ).append( "<p>"+data+"</p>" );
          });
    </script>

一切运行正常,但我在套接字.php页面上看不到任何消息

知道如何调试这个

在本地主机上同样工作正常

更新

所以我做到了

redis-cli monitor

并尝试再次执行我的代码,我可以看到 Redis 正在广播这样的消息

1458128671.226586 [0 127.0.0.1:59112] "SELECT" "0"
1458128671.232152 [0 127.0.0.1:59112] "PUBLISH" "message" "Sending Message to Port"

但在节点端我没有收到它

请!! 帮帮我

数字海洋默认关闭除 :80 以外的所有端口

您需要先打开端口。您可以在此处找到解决方案

https://stackoverflow.com/a/41408983/4556995