zeabur-port-mismatch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseZeabur Port Mismatch
Zeabur端口不匹配
Always useto invoke Zeabur CLI. Never usenpx zeabur@latestdirectly or any other installation method. Ifzeaburis not available, install Node.js first.npx
请始终使用调用Zeabur CLI。 切勿直接使用npx zeabur@latest或其他任何安装方式。如果zeabur不可用,请先安装Node.js。npx
Symptom
症状
dial tcp 10.x.x.x:3000: i/o timeout
dial tcp 10.x.x.x:80: connection refuseddial tcp 10.x.x.x:3000: i/o timeout
dial tcp 10.x.x.x:80: connection refusedCause
原因
Proxy expects service on port X, but service listens on port Y.
代理期望服务运行在端口X,但实际服务监听在端口Y。
Diagnose
诊断步骤
- Check port forwarding status and actual forwarded ports:
bash
npx zeabur@latest service network --id SERVICE_ID - Check what port the container is actually listening on:
(use thebash
npx zeabur@latest service exec --id SERVICE_ID -- netstat -tlnpskill to also check logs for port binding info)zeabur-deployment-logs - Check what port proxy expects (from Caddyfile/nginx.conf)
- Check what port container exposes (Dockerfile )
EXPOSE
- 检查端口转发状态及实际转发端口:
bash
npx zeabur@latest service network --id SERVICE_ID - 检查容器实际监听的端口:
(也可使用bash
npx zeabur@latest service exec --id SERVICE_ID -- netstat -tlnp技能查看日志中的端口绑定信息)zeabur-deployment-logs - 检查代理期望的端口(从Caddyfile/nginx.conf中查看)
- 检查容器暴露的端口(Dockerfile中的指令)
EXPOSE
Common Mismatches
常见不匹配场景
| Proxy expects | Container has | Fix |
|---|---|---|
| nginx default | Change template port to 80 |
| app on | Change template port to 3000 |
| 代理期望 | 容器实际配置 | 修复方案 |
|---|---|---|
| nginx默认 | 将模板端口改为80 |
| 应用运行在 | 将模板端口改为3000 |
Fix in Template
在模板中修复
Use the skill for full YAML reference on port configuration and :
zeabur-templateportForwardingyaml
ports:
- id: web
port: 3000 # Match what container actually exposes
type: HTTPCheck official Dockerfile for directive.
EXPOSE使用技能获取端口配置和的完整YAML参考:
zeabur-templateportForwardingyaml
ports:
- id: web
port: 3000 # 与容器实际暴露的端口保持一致
type: HTTP请查看官方Dockerfile中的指令。
EXPOSEHeadless Service (502 with no listener)
无头服务(无监听导致502错误)
Symptom
症状
Service is running (no crash), but proxy returns 502 Bad Gateway permanently.
服务正在运行(未崩溃),但代理持续返回502 Bad Gateway错误。
Cause
原因
Service does not listen on any HTTP port. Examples: chatbot gateways, background workers, message queue consumers. The template declares an HTTP port but nothing binds to it.
服务未监听任何HTTP端口。例如:聊天机器人网关、后台工作进程、消息队列消费者。模板中声明了HTTP端口,但没有进程绑定到该端口。
Fix
修复方案
Add a lightweight HTTP health check server that runs in the background alongside the main process:
bash
undefined添加一个轻量级HTTP健康检查服务器,与主进程一起在后台运行:
bash
undefinedStart before main process in startup script
在启动脚本中先启动该服务
IMPORTANT: port must match spec.ports[].port in your template
重要:端口必须与模板中spec.ports[].port的配置一致
python3 -c "
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
class H(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-Type','application/json')
self.end_headers()
self.wfile.write(json.dumps({'status':'ok'}).encode())
def log_message(self,*a): pass
HTTPServer(('0.0.0.0', 8080), H).serve_forever()
" &
exec my-headless-app
undefinedpython3 -c "
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
class H(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-Type','application/json')
self.end_headers()
self.wfile.write(json.dumps({'status':'ok'}).encode())
def log_message(self,*a): pass
HTTPServer(('0.0.0.0', 8080), H).serve_forever()
" &
exec my-headless-app
undefinedPort Forwarding Not Working
端口转发不生效
If a TCP service is deployed but not reachable externally:
- Check if port forwarding is enabled:
bash
npx zeabur@latest service port-forward --id SERVICE_ID - Enable it if disabled:
bash
npx zeabur@latest service port-forward --id SERVICE_ID --enable - Verify the forwarded endpoint:
bash
npx zeabur@latest service network --id SERVICE_ID # Output: proxy (TCP 8888) → 34.x.x.x:20143
如果TCP服务已部署但外部无法访问:
- 检查端口转发是否已启用:
bash
npx zeabur@latest service port-forward --id SERVICE_ID - 若未启用则开启:
bash
npx zeabur@latest service port-forward --id SERVICE_ID --enable - 验证转发端点:
bash
npx zeabur@latest service network --id SERVICE_ID # 输出示例:proxy (TCP 8888) → 34.x.x.x:20143