【问题标题】:Firefox Keep-Alive, Upgrade ruining websocket through apache reverse proxyFirefox Keep-Alive,通过 apache 反向代理升级破坏 websocket
【发布时间】:2016-03-01 09:58:32
【问题描述】:

我有以下适用于 chrome 和 Internet Explorer 的 apache2 配置:

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>

问题是它不能通过 firefox 工作。

我看到的唯一区别是 Firefox 发送 Connection: keep-alive, Upgrade 而不是简单的 Upgrade

我需要更改我的重写规则吗?

【问题讨论】:

    标签: apache firefox websocket


    【解决方案1】:

    是的,您需要在重写规则中添加一个条件。以下配置将在检查 Upgrade keep-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]
    

    【讨论】:

    • 我真的很想让这个工作,但似乎没有。我错过了什么吗?
    • 确保将 websocket URL 和端口更改为目标。我在 Firefox 中使用这个配置没有问题
    • 对我有用的是在^Upgrade$ 上删除^。见这里stackoverflow.com/a/34371105/1274820
    猜你喜欢
    • 2019-05-25
    • 2016-09-07
    • 2017-09-19
    • 2015-01-13
    • 2015-07-22
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多