带代理的 WSS 使用端口 443 浏览器客户端连接到端口 6001 上的 websocket 服务器

WSS with proxy using port 443 browser client connect to websocket server on port 6001

我正在使用“laravel websocket if beyondcode”让浏览器客户端在端口 6001 上提供 WebSocket 服务。但是当我将浏览器客户端请求更改为使用端口 80/443 时,它没有连接到 WebSocket 服务器。

浏览器客户端请求URL:

wss://test.example.com:443/app/ABCDEFG?protocol=7&client=js&version=7.0.3&flash=false

标签中添加的代码

SSLProxyEngine on
ProxyPreserveHost On
ProxyPass /app wss://test.example.com:6001/
ProxyPassReverse /app wss://test.example.com:6001/
ProxyRequests off

谁能帮我解决这个问题?

这是在我的 centos 中运行的最终工作代码。

在关闭 标签之前添加以下代码

<IfModule mod_proxy.c>
    ProxyRequests Off
    SSLProxyEngine On

    # Ensure WebSocket protocol is forwarded correctly
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^Websocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule /app/(.*) wss://%{HTTP:HOST}:6001/app/ [P]
</IfModule>

下面是我的推送设置

window.pusher = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    encrypted: false,
    wsHost: window.location.hostname,
    // commented this because it should be use default port 80/443
    //wsPort: process.env.MIX_LARAVEL_WEBSOCKETS_PORT,
    //wssPort:process.env.MIX_LARAVEL_WEBSOCKETS_PORT,
    enabledTransports: ['ws', 'wss'],
    forceTLS: true,
});