apache - Websocket 在 Chrome 上连接,但不在 Firefox 上连接

标签 apache firefox websocket proxypass

我正在开发 WebSockets 的 apache 代理,连接在 Chrome 和 Safari Mobile 上运行良好,但 Firefox 返回 200 Ok 状态并断开连接。

有问题的服务器是一台运行 Apache 的 Centos 7 服务器,而 websocket 由 NodeJS 提供。

<VirtualHost *:443>
    ServerAdmin webmaster@example.com
    ServerName alpha.example.com
    ServerAlias www.alpha.example.com
    DocumentRoot public_html/
    ErrorLog logs/error.log

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    SSLProxyEngine On

    Include cert.pem
    SSLCertificateKeyFile privkey.pem
    SSLCertificateChainFile chain.pem

    ProxyRequests Off

    RewriteEngine On

    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
    RewriteRule .* ws://localhost:8080%{REQUEST_URI} [P]

    ProxyPass /ws http://127.0.0.1:8080
    ProxyPassReverse /ws http://127.0.0.1:8080

</VirtualHost>

Chrome 连接到服务器,我可以双向发送事件。 Firefox 尝试连接但随后立即关闭并显示 200 Ok 状态但记录 Firefox can’t establish a connection to the server at wss://alpha.example.com/.然而,Firefox 可以加载代理请求,如 https://alpha.example.com/ws

最佳答案

该行为是由于不同的 Connection GET 调用中的 header 。
对于 Chrome 是:

Connection: Upgrade
而对于 Firefox 是
Connection: keep-alive, Upgrade
因此,您需要更改 Connection 的 RewriteCond到:
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
另请参阅:https://stackoverflow.com/a/34371105/2186777

关于apache - Websocket 在 Chrome 上连接,但不在 Firefox 上连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54406008/

相关文章:

wordpress - 混合内容/不安全内容 SSL

python - 套接字连接在 3 次迭代后中止 - python

javascript - 握手期间 ASP.NET Core WebSocket 失败

javascript - AWS websocket 服务器 : 403 error when connecting from browser, 来自 Python

php - 编辑 httpd.conf 以在 mac 上使用 apache 服务器

php - 在 url 中,用什么来替换空格、+ 或破折号更好? url encode 做 + ,谷歌推荐破折号

apache - 如何在 apache2 中禁用 mod_deflate?

javascript - 主线程上的同步 XMLHttpRequest 已弃用

c++ - 如何检查系统上是否安装了特定的网络浏览器?

javascript - SVG 中 Firefox 中的 onmouseover 事件