【问题标题】:Websocket is connecting on Chrome but not on FirefoxWebsocket 在 Chrome 上连接,但在 Firefox 上没有
【发布时间】:2019-06-21 16:37:29
【问题描述】:

我正在开发 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

【问题讨论】:

    标签: apache firefox websocket proxypass


    【解决方案1】:

    该行为是由于 GET 调用中的 Connection 标头不同所致。

    对于 Chrome 是:

    Connection: Upgrade
    

    而对于 Firefox 是

    Connection: keep-alive, Upgrade
    

    因此,您需要将 Connection 的 RewriteCond 更改为:

    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    

    另请参阅:https://stackoverflow.com/a/34371105/2186777

    【讨论】:

      猜你喜欢
      • 2019-02-27
      • 2014-10-13
      • 2018-11-15
      • 2022-08-15
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2013-11-22
      • 2014-07-09
      相关资源
      最近更新 更多