首页 > 解决方案 > 通过 Apache 反向代理代理驾驶舱

问题描述

我正在尝试使用 Apache 代理 cockpit[1],

它打开登录界面,但是登录后我得到一个空白屏幕,没有错误,什么都没有。在 devtools 中我发现了一个 ws 错误Error during WebSocket handshake: Unexpected response code: 400

cockpit-ws 守护进程在它的日志中输出这个

cockpit-ws[14523]: received invalid or missing Upgrade header: (null)
cockpit-ws[14523]: Received invalid handshake request from the client
cockpit-ws[14523]: WebSocket from 192.168.123.2 for session closed

我在 Centos7 上运行 cockpit 195

这里是相关的配置部分

ProxyPreserveHost On                                     
ProxyRequests Off                                        

# allow for upgrading to websockets                      
RewriteEngine On                                         
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]             
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]            
RewriteRule .* ws://192.168.123.2:9090/%{REQUEST_URI} [P]

# Proxy to your local cockpit instance                   
ProxyPass / http://192.168.123.2:9090/                   
ProxyPassReverse / http://192.168.123.2:9090/            

是的,我没有使用我知道的虚拟主机,我试图让它在/cockpiturl 上工作,但这是另一个问题

这是/etc/cockpit/cockpit.conf

[WebService]                                                                                         
Origins = https://192.168.123.2:9090 wss://192.168.123.2:9090 http://192.168.123.2 ws://192.168.123.2
ProtocolHeader = X-Forwarded-Proto                                                                   
AllowUnencrypted = true                                                                              

[1] https://cockpit-project.org/

标签: cockpit

解决方案


有同样的问题,我忘了启用 proxy_wstunnel 模块。

sudo a2enmod proxy proxy_wstunnel proxy_http ssl rewrite

此处描述了整个 Apache 代理设置 https://github.com/cockpit-project/cockpit/wiki/Proxying-Cockpit-over-Apache-with-LetsEncrypt


推荐阅读