簡體   English   中英

如何配置Ubuntu服務器以將Node.js用於WebSocket,將Apache2用於其他所有功能?

[英]How can I configure Ubuntu Server to use Node.js for WebSockets, and Apache2 for everything else?

我有一個使用Node.js和WS軟件包構建的非常簡單的WebSocket服務器。

var WebSocketServer = require('ws').Server
var wss             = new WebSocketServer({
        port: 8080
    });

wss.on('connection', function(client) {

    client.on('message', function(message) {
        console.log('received: %s', message);
    });

    client.send('something');
});


// Console will print the message
console.log('-=-=- Server running :8080 -=-=-');

當我嘗試使用簡單的客戶端進行連接時,連接超時。

<script>
    var ws = new WebSocket('ws://192.168.1.75:8080');

    ws.onconnect = function(){
        console.log("Connected!");
    };


</script>

服務器啟動/運行沒有錯誤,但是客戶端始終使連接超時。 我是否需要配置iptables或apache以將端口8080上的流量發送到我編寫的節點服務器? 我當時以為服務器會自動開始偵聽8080端口。(如果這是一個過時的問題,我事先表示歉意。我對Node.js非常陌生)

只要在同一端口上沒有任何Apache流量,就不必對Apache進行任何特殊處理。 您將只有兩個單獨的服務器同時在單獨的端口上運行,並且必須相應地引導您的流量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM