没有对 URL /(方案“ws”)有效的协议处理程序

没有对 URL /(方案“ws”)有效的协议处理程序

尝试使用 apache2 设置 websocket 代理时出现以下错误:

对于 URL /(方案“ws”),没有有效的协议处理程序。如果您使用的是 mod_proxy 的 DSO 版本,请确保使用 LoadModule 将代理子模块包含在配置中

apache服务器的wstunnel模块被加载了,下面是结果apache2ctl -M

Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
headers_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php7_module (shared)
proxy_module (shared)
proxy_connect_module (shared)
proxy_fcgi_module (shared)
proxy_html_module (shared)
proxy_http_module (shared)
proxy_wstunnel_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
socache_shmcb_module (shared)
ssl_module (shared)
status_module (shared)
xml2enc_module (shared)

答案1

我也遇到了这个错误。当我将 HTTPS 请求代理到 WS 协议时,发生了这种情况。当我拆分代理以将 HTTPS 请求转发到 HTTP 并将 WSS 请求转发到 WS 时,错误消失了。

为此,我配置了 mod_rewrite 来查找Upgrade: websocketHTTP 标头。当 HTTP 标头存在时,它会代理协议ws:;当 HTTP 标头不存在时,它会代理http:协议。

<VirtualHost *:443>
    Servername sub.example.com
    Include include/ssl.conf
    
    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://localhost:1080/$1 [P,L]
    RewriteRule /(.*) http://localhost:1080/$1 [P,L]
</VirtualHost>

相关内容