项目

通用

个人资料

操作

mod_wstunnel

模块:mod_wstunnel

(自 lighttpd 1.4.46 起)

WebSocket 隧道端点。此模块终止来自客户端的 WebSocket 隧道。然后,此模块将数据(不带 WebSocket 帧)传递到后端,并在将响应发送到客户端之前,将来自后端的响应编码为 WebSocket 帧。

注意:如果要将 WebSocket 发送到后端,请参阅WebSockets,其中包含使用mod_proxymod_cgimod_scgimod_fastcgi的示例。

描述

mod_wstunnel 指令的简要说明

选项 描述
wstunnel.server 用于向其发送请求的主机的后端服务器定义;每个后端主机的选项
wstunnel.balance 后端的负载均衡算法(“公平”、“最少连接”、“轮询”、“哈希”或“粘性”)
wstunnel.debug 调试级别(0 到 65535 之间的值)
wstunnel.frame-type WebSocket 帧类型:“text”或“binary”
wstunnel.map-extensions 将多个扩展映射到同一后端
wstunnel.origins Origin 请求头中允许的源列表(可选)
wstunnel.ping-interval 以给定秒数间隔发送 WebSocket PING 帧(默认 0;不发送)

有关 wstunnel.server 参数的详细信息,请参阅 mod_fastcgi 文档,因为 wstunnel 模块与 FastCGI 模块共享相同的代码基础设施,并且 fastcgi.server 参数非常相似。

示例:通过 noVNC 客户端连接 VNC 服务器的 WebSocket 隧道

请按照说明下载并安装,或使用适用于您的 Linux/*BSD 发行版的可用软件包。
https://github.com/novnc/noVNC
x11vnc

如果 noVNC 文件安装在 /usr/share/novnc 中,并且 x11vnc 作为 VNC 服务器运行,并使用 x11vnc -localhost -forever -display :0 命令,则可以配置 lighttpd mod_wstunnel。

server.document-root = "/usr/share/novnc" 
server.indexfiles = ("index.html")
server.modules += ( "mod_wstunnel" )
$HTTP["url"] =~ "^/websockify" {
    wstunnel.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "5900" ) ) )
    wstunnel.frame-type = "binary" 
}

请采取适当的预防措施来限制对 VNC 服务器的访问,可能包括要求适当的身份验证和限制对某些源 IP 的访问。

示例:连接到一个简单的“echo”脚本的 WebSocket 隧道,该脚本逐行读取并回显

WebSockets:示例:echo.pl

gstrauss1 年多前更新 · 17 次修订