【问题标题】:ws protocol and apache mod_proxy_wstunnel configuration: error 500ws 协议和 apache mod_proxy_wstunnel 配置:错误 500
【发布时间】:2016-10-09 07:43:40
【问题描述】:

尝试通过我的 Apache2 服务器访问 ws://localhost:8080/ 时出现错误 500。此服务器运行 OpenSuse Leap 42.1 和 Apache 2.4.16。

这些 Apache2 模块已启用:mod_proxy、mod_proxy_http、mod_proxy_wstunnel。

当从本地网络调用请求时,一切正常。 URL 示例:http://<myhost-ip-address>/api/ws/<some-url>。它返回状态 101 和响应:Upgrade: websocket。没关系。

来自外部网络的同种请求失败。 URL 示例:ws://www.mysite.com/api/ws/<some-url>。它返回错误 500。

Apache 访问日志包含:GET /api/ws/<some-url> HTTP/1.1" 500 ...

Apache 错误日志包含:[proxy:warn] AH01144: No protocol handler was valid for the URL /api/ws/<some-url>. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

我的 httpd.conf:

<VirtualHost *:80>
ServerName mysite.com
ServerAlias mysite.com
# Redirection for ws protocol
ProxyPreserveHost On
ProxyVia full
ProxyRequests OffHere
RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/api/ws/(.*)           [NC]
RewriteCond %{QUERY_STRING} transport=websocket     [NC]
RewriteRule /(.*)           ws://localhost:8080/$1  [P,L]
# Proxy pass
ProxyPass           /api/ws/            ws://localhost:8080/api/ws/
ProxyPassReverse    /api/ws/            ws://localhost:8080/api/ws/
# DocumentRoot
DocumentRoot /srv/www/vhosts/mysite.com
<Directory "/srv/www/vhosts/mysite.com">
    Options Indexes SymLinksIfOwnerMatch
    AllowOverride None
    ...
</Directory>
# URL as parameter
AllowEncodedSlashes NoDecode

我遵循了这些以前的 StackOverflow 答案(感谢): websocketsnode.jssocket-io,但没有运气。

我的配置一定有问题。有什么想法吗?

编辑

按照adona9的建议,这里是调试日志:

proxy_util.c(1784): AH00925: initializing worker ws://localhost:8080/api/ws/ shared
proxy_util.c(1826): AH00927: initializing worker ws://localhost:8080/api/ws/ local
...
mod_authz_core.c(809): AH01626: authorization result of Require user <user>: granted
mod_authz_core.c(809): AH01626: authorization result of <RequireAny>: granted
mod_charset_lite.c(219): AH01448: incomplete configuration: src unspecified, dst unspecified
mod_proxy.c(1159): AH01143: Running scheme ws handler (attempt 0)
mod_proxy_http.c(1944): AH01113: HTTP: declining URL ws://localhost:8080/api/ws/<some-url>
mod_proxy_wstunnel.c(341): AH02900: declining URL ws://localhost:8080/api/ws/<some-url>  (not WebSocket)
[proxy:warn] H01144: No protocol handler was valid for the URL /api/ws/<some-url>. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

有什么想法吗?

【问题讨论】:

  • 您是否尝试过将 LogLevel 设置为调试并检查错误日志?您应该会看到其他方案正在下降,并且 proxy_wstunnel 为您的请求的 URL 提供服务。
  • @adona9 : 我在编辑后的帖子中添加了调试日志。
  • 我有同样的问题,因为“AllowEncodedSlashes NoDecode”我不知道为什么,但是在一段时间后使用这个参数 ws:// 停止工作。
  • 你们解决过这个问题吗?

标签: apache websocket mod-proxy


【解决方案1】:

所以我最终花了一天半的时间研究和阅读深度 apache2 配置。这就是我能够解决这个问题的方法:

  • 同时使用 forensic_logs 和 DumpIO 在 apache2 端找出我的初始请求标头。

  • 记录来自 websocket 客户端的请求头。

验证请求标头中都包含升级标头和连接类型 websocket。这些问题很可能是网络过滤或删除特定头文件的结果。

我的问题是我使用的 AWS 经典负载均衡器不支持 websocket 连接。

在阅读其他论坛时,一些公司的防火墙也会从他们的连接中删除特定的头文件,所以也可能是这样。

因此,如果您已经三重检查以确保安装了正确的模块,则很可能是网络相关的错误。

如果你有网络图,检查每个特定的节点和网关,并验证输入和输出请求头是否相同。

【讨论】:

  • 感谢您对所有这些伟大的调查。但我从 2017 年开始在一家新公司工作。我暂时无法检查。其他人可以验证,以便我可以将此答案标记为已接受吗?
猜你喜欢
  • 2015-02-16
  • 2019-07-15
  • 1970-01-01
  • 1970-01-01
  • 2019-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多