ws 协议和 apache mod_proxy_wstunnel 配置:错误 500

jac*_*k-y 7 mod-proxy apache-2.4 websocket

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

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

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

来自外网的同类请求失败。网址示例: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
Run Code Online (Sandbox Code Playgroud)

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

我的配置一定有问题。有任何想法吗?

ser*_*com 3

看起来您缺少 Websockets 支持所需的 mod_proxy_wstunnel 模块。

它应该在您的 httpd.conf 中启用,如下所示

LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
Run Code Online (Sandbox Code Playgroud)

安装模块然后它应该可以正常工作。