
Portainer 无法进入容器控制台 [已解决]
版主: TerraSupport, TMsupport, TMjack
Re: Portainer 无法进入容器控制台
Portainer 的 Nginx 配置文件中缺少 WebSocket 连接所需的标头,导致 Portainer 终端连接失败,您可以部署下面这个容器,它会自动检查并修补 Nginx 配置,然后就可以连接终端了。
代码: 全选
version: '3'
services:
nginx-fixer:
image: alpine:latest
container_name: nginx-websocket-fix
restart: always
pid: host
volumes:
- /etc/nginx/conf.d:/host_conf_d
entrypoint:
- /bin/sh
- -c
- |
echo "Checking Portainer Nginx config..."
CONF="/host_conf_d/portainer.conf"
# 1. Check if file exists and needs patching
if [ -f "$$CONF" ] && ! grep -q "proxy_set_header Upgrade" "$$CONF"; then
echo "Fix missing. Applying patch..."
# Insert the websocket headers before the proxy_pass line
# Note: We use $$ to escape variables in docker-compose
sed -i '/proxy_pass/i \ proxy_http_version 1.1;\n proxy_set_header Upgrade $$http_upgrade;\n proxy_set_header Connection "Upgrade";' "$$CONF"
echo "Patch applied. Reloading Host Nginx..."
# Send HUP signal to host nginx processes to reload config
kill -HUP $$(pidof nginx)
else
echo "Config is already patched or missing."
fi
# 2. Sleep forever to keep container "Running" so it starts on next boot
echo "Job done. Sleeping to maintain 'Running' status for next reboot..."
sleep infinity联系我们的团队,请发送电子邮件到以下地址,记住用@代替(at):
技术团队:support(at)terra-master.com(技术支持)
服务团队:Service(at)terra-master.com(用于购买,退货,更换,RMA服务)
技术团队:support(at)terra-master.com(技术支持)
服务团队:Service(at)terra-master.com(用于购买,退货,更换,RMA服务)
