火狐浏览器保持连接,升级通过Apache反向代理破坏WebSocket

3
我有以下的apache2配置,适用于chrome和internet explorer:

我有以下的apache2配置,适用于chrome和internet explorer:

Listen 80

IncludeOptional conf.d/*.conf
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

<VirtualHost *:80>
        #ProxyRequests On
        ProxyPass / http://IP:8585/
        ProxyPassReverse / http://IP:8585/

        ProxyPass /call  ws://IP:8585/call
        ProxyPassReverse /call  ws://IP:8585/call

        ProxyPass /call/  ws://IP:8585/call/
        ProxyPassReverse /call/  ws://IP:8585/call/

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

</VirtualHost>

问题在于它不能通过火狐浏览器工作。

我发现唯一的区别是火狐浏览器发送了 Connection: keep-alive, Upgrade 而不仅仅是 Upgrade

我需要改变我的Rewriterule吗?

1个回答

1

是的,您需要在重写规则中添加条件。以下配置将起作用,因为它检查Upgradekeep-alive, Upgrade连接值:

RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^keep-alive,\ Upgrade$ [NC]
RewriteRule .* ws://localhost:8585%{REQUEST_URI} [P]

我真的很想让它工作,但似乎并没有。我错过了什么吗? - user1274820
请确保将WebSocket的URL和端口更改为您的目标。我正在使用这个配置,而且在Firefox上没有任何问题。 - Jon Ruddell
对我有效的方法是删除 ^Upgrade$ 中的 ^。请参见此处 https://dev59.com/qXzaa4cB1Zd3GeqPV-U-#34371105 - user1274820

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接