【问题标题】:Intermittent Web Sockets error with Apache reverse proxyApache 反向代理的间歇性 Web 套接字错误
【发布时间】:2015-08-02 03:15:32
【问题描述】:

我已将 Apache 设置为将 Web 套接字请求反向代理到 JVM 服务器。有时他们工作。有时(很少,但有时)它们不起作用。这具有海森虫的特征。

客户:

socket = new WebSocket("ws://example.com/socket/xyz");
socket.onmessage = function(item) {});

有时这有效。有时它不会。如果没有,我会收到错误消息:

WebSocket connection to 'ws://example.com/websocket' failed:
Error during WebSocket handshake: Invalid status line

当 Chrome 调试控制台打开时,这始终有效。它有时会失败,但有时会失败。

我的 Apache 配置是最小的:

<VirtualHost *:80>
  ServerName      example.com
  AllowEncodedSlashes On
  ErrorLog         /var/log/apache2/example
  TransferLog      /var/log/apache2/example
  UseCanonicalName On

  ProxyRequests Off
  ProxyPreserveHost On
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass        /socket/ ws://upstream.host/socket/
  ProxyPassReverse /socket/ ws://upstream.host/socket/
  ProxyPass        / http://upstream.host/
  ProxyPassReverse / http://upstream.host/
  <Location />
    Order allow,deny
    Allow from all
  </Location>
</VirtualHost>

所以我无法进入网络检查器查看发生了什么。没有让 Wireshark 参与进来,我有点卡住了。

我在 Apache 错误日志中看不到任何错误。

我在我的应用程序日志中看不到任何错误。

我唯一的想法是 Chrone 开发者控制台以某种方式阻止了某种竞争条件,但我想不出是什么。

我在服务器上使用 HTTP-Kit 库,在客户端使用 React.js。我想是 proxy_wstunnel 在 Apache2 中工作。

有什么想法吗?

【问题讨论】:

    标签: websocket apache2 virtualhost reverse-proxy mod-proxy


    【解决方案1】:

    我在使用 Apache (v2.4.6) 的代理传递模块时遇到了同样的问题,三个、四个连接同时按预期工作,但是每秒多次请求失败。似乎该模块仍然有点错误。

    也许不能直接解决您的问题,但我切换到HAProxy,现在一切正常。

    【讨论】:

    • 我发现 proxy_wstunnel_module 中有一些错误,在我的情况下,使用带有 EnableWsTunnel 的 mod_cluster 具有提到的相同行为。
    猜你喜欢
    • 2020-08-05
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 2022-06-10
    • 2012-08-13
    • 1970-01-01
    • 2016-04-28
    相关资源
    最近更新 更多