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