大网数据广告活动
服务器运维问答

No protocol handler was valid for the URL / (scheme 'ws')

· 52CE 我爱测

Trying to setup a websocket proxy using apache2, I get the following error: No protocol handler was valid for the URL / (scheme 'ws'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in th…

问题原文

原帖链接 · Mohsen Saberi · CC BY-SA 4.0

Trying to setup a websocket proxy using apache2, I get the following error:

No protocol handler was valid for the URL / (scheme 'ws'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule

The wstunnel module of the apache server is loaded. The following is the result of 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)

社区高分解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

I was getting that error as well. It happened when I proxying HTTPS requests to WS protocol. The error went away when I split the proxy to forward HTTPS requests to HTTP and WSS requests to WS.

To do so, I configured mod_rewrite to look for the Upgrade: websocket HTTP header. When it is present, it proxies the ws: protocol, when it is not present it proxies the http: protocol.

<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>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-11-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。