使用lighttpd重定向端口80上的websocket流量 [英] Redirecting websocket traffic on port 80 with lighttpd

查看:451
本文介绍了使用lighttpd重定向端口80上的websocket流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个托管在lighttpd上的网站,可以在"www"子域中访问.我也有一个聊天服务器,侦听由node.js和socket.io制成的8124端口.

I have a website hosted on lighttpd, accessible at the "www" subdomain. I also have a chat server listening on port 8124 made with node.js and socket.io.

我希望所有客户端流量都通过将所有请求重定向到聊天"子域到端口8124来在端口80上发生.因此,我启用了mod_proxy并在lighttpd.conf中添加了:

I want all client traffic to happen on port 80, by redirecting all requests to the "chat" subdomain to port 8124. So I enabled mod_proxy and in lighttpd.conf I added:

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

在客户端上,当我连接到网络套接字时,

On the client, when I connect to the websocket,

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

我从node.js得到正确的消息:

I get the right messages from 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::

但是浏览器给出了一个错误:

But the browser gives an error:

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

当然,如果我直接连接到端口8124,一切都可以正常工作:

Of course, everything works correctly if I connect directly to the port 8124:

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

但是,正如我所说,我希望所有客户端流量都在端口80上.这是否可能?

But, as I said, I would like all client traffic to be on port 80. Is it possibile?

推荐答案

mod_proxy与Websocket不兼容.

mod_proxy is known to be not compatible with websockets.

HAProxy 是兼容的(我自己尚未对其进行测试,但这是一个

HAProxy is compatible (I haven't tested it myself but here's an article on its configuration for websockets).

这篇关于使用lighttpd重定向端口80上的websocket流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆