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

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

问题描述

我在 lighttpd 上托管了一个网站,可通过www"子域访问.我还有一个聊天服务器监听 8124 端口,使用 node.js 和 socket.io.

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.

我希望所有客户端流量都发生在端口 80 上,通过将所有请求重定向到聊天"子域到端口 8124.所以我启用了 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"
            ))
    )
}

在客户端,当我连接到 websocket 时,

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::

但是浏览器报错:

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 已知与 websockets 不兼容.

mod_proxy is known to be not compatible with websockets.

HAProxy 是兼容的(我自己没有测试过,但这里有一个 关于 websockets 配置的文章).

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天全站免登陆