Websocket正在Chrome而非Firefox上进行连接

时间:2019-01-28 16:08:22

标签: 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正常状态关闭,但记录Firefox can’t establish a connection to the server at wss://alpha.example.com/.,但Firefox可以加载https://alpha.example.com/ws之类的代理请求

1 个答案:

答案 0 :(得分:0)

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

Chrome浏览器为:

Connection: Upgrade

而Firefox是

Connection: keep-alive, Upgrade

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

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

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