You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker配置Centrifugo后localhost:8427无法访问求助

Centrifugo Docker部署后localhost:8427无法访问的排查建议

尝试用Docker配置Centrifugo,启动容器后执行curl localhost:8427返回页面未找到,无法访问服务,可按以下步骤排查:

  • 确认访问路径有效性:Centrifugo默认没有根路径(/)的响应,直接访问localhost:8427返回404是正常现象。请尝试访问以下有效端点:

    • 管理界面:localhost:8427/admin(需使用配置的admin_password登录)
    • 健康检查:localhost:8427/health
    • WebSocket连接:ws://localhost:8427/connection/websocket
    • Debug端点(已开启debug模式):localhost:8427/debug/pprof
  • 验证端口映射状态:

    • 执行docker ps查看容器端口映射,确认存在0.0.0.0:8427->8427/tcp或[::]:8427->8427/tcp的记录
    • 进入容器内部测试连通性:执行docker exec -it tradegame_backend_local_centrifugo curl localhost:8427/health,若返回OK则说明容器内服务正常运行
  • 检查Redis依赖连接:

    • 日志显示Centrifugo尝试连接redis://redis:6379/1,需确认Docker Compose中是否包含名为redis的服务,且该服务已正常启动
    • 查看Redis容器日志,确认Redis服务运行正常、无连接失败情况
  • 核对配置文件挂载正确性:

    • 检查本地centrifugo.json文件是否存在,路径是否与docker-compose.yml中./centrifugo.json:/centrifugo/config.json的配置一致
    • 执行docker exec -it tradegame_backend_local_centrifugo cat /centrifugo/config.json,确认容器内的配置文件与本地文件内容完全匹配

用户提供的配置信息

docker-compose.yml

centrifugo:
  image: centrifugo/centrifugo:v4.0.4
  container_name: tradegame_backend_local_centrifugo
  command: centrifugo -c /centrifugo/config.json
  expose: 
    - 8427
  ports:
    - "8427:8427"
  volumes:
    - "./centrifugo.json:/centrifugo/config.json"
  ulimits:
    nproc: 65536
    nofile:
      soft: 65536
      hard: 65536

容器日志

local_centrifugo  | {"level":"info","version":"4.0.4","runtime":"go1.19.3","pid":1,"engine":"redis","gomaxprocs":8,"time":"2023-12-18T17:43:30Z","message":"starting Centrifugo"}
local_centrifugo  | {"level":"info","path":"/centrifugo/config.json","time":"2023-12-18T17:43:30Z","message":"using config file"}
local_centrifugo  | {"level":"info","algorithms":"HS256, HS384, HS512","time":"2023-12-18T17:43:30Z","message":"enabled JWT verifiers"}
local_centrifugo  | {"level":"info","time":"2023-12-18T17:43:30Z","message":"Redis: redis:6379/1, using password: false"}
local_centrifugo  | {"level":"warn","time":"2023-12-18T17:43:30Z","message":"DEBUG mode enabled, see /debug/pprof"}
local_centrifugo  | {"level":"warn","time":"2023-12-18T17:43:30Z","message":"usage of allowed_origins * is discouraged for security reasons, consider setting exact list of origins"}
local_centrifugo  | {"level":"info","time":"2023-12-18T17:43:30Z","message":"serving websocket, API, debug endpoints on :8427"}

Centrifugo config.json

{
    "v3_use_offset": true,
    "token_hmac_secret_key": "XXXXXXXXXXXX",
    "admin_password": "XXXXXXXXXXXX",
    "admin_secret": "XXXXXXXXXXXX",
    "api_key": "XXXXXXXXXXXX",
    "port": "8427",
    "debug": true,
    "allow_subscribe_for_client": true,
    "allow_subscribe_for_anonymous": true,
    "user_subscribe_to_personal": true,
    "user_personal_single_connection": false,
    "user_personal_channel_namespace": "personal",
    "namespaces": [
      {
        "name": "personal",
        "presence": true
      }
    ],
    "engine": "redis",
    "redis_address": "redis://redis:6379/1",
    "user_status": {
      "enabled": true,
      "use_redis_from_engine": true
    },
    "allowed_origins": [
      "*"
    ]
  }

内容的提问来源于stack exchange,提问作者Kogelet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 17:57:03