2012-06-08 117 views
7

我有一個託管在lighttpd上的網站,可以在「www」子域訪問。我還有一個聊天服務器監聽使用node.js和socket.io製作的端口8124。使用lighttpd重定向端口80上的websocket流量

我希望所有客戶端的流量發生在端口80,通過重定向所有請求到「聊天」子域名端口8124所以我啓用的mod_proxy和lighttpd.conf我說:

$HTTP["host"] == "chat.myserver.com" { 
    proxy.server = (
      "" => ((
        "host" => "78.128.79.192", 
        "port" => "8124" 
      )) 
    ) 
} 

在客戶端,當我連接到的WebSocket,

var socket = io.connect('http://chat.myserver.com'); 

我從node.js中得到正確的信息:

debug - client authorized 
info - handshake authorized 6067470561567883577 
debug - setting request GET /socket.io/1/websocket/6067470561567883577 
debug - set heartbeat interval for client 6067470561567883577 
debug - client authorized for 
debug - websocket writing 1:: 

但瀏覽器提供了一個錯誤:

Firefox can't connect to server ws://chat.myserver.com/socket.io/1/websocket/6067470561567883577 

當然,一切工作正常,如果我直接連接到端口8124:

var socket = io.connect('http://www.myserver.com:8124'); 

但是,正如我所說,我想所有客戶端流量在端口80上。它可能嗎?

回答

7

mod_proxy已知與websockets不兼容。

HAProxy是兼容的(我沒有自己測試過,但是這裏是article on its configuration for websockets)。

+3

我剛剛安裝了Haproxy,它的工作完美。謝謝 – lortabac

+0

不客氣。並感謝確認,因爲我沒有測試它(如我所說),並期待着它:) –

+0

嗨!我目前正在嘗試使用socket.io製作websocket與lighttpd一起使用,並且我正面臨一個問題。它似乎無法連接到'ws:// /socket.io/1/ <隨機數字> /:'連接'標題丟失'。你說的HAProxy的conf文件是什麼樣的(而不是lighttp mod_proxy)。非常感謝! – D4V1D