当前位置: 首页 > news >正文

140. 如何使用 nginx /dbg

What is the /dbg command?
什么是 /dbg 命令?

/dbg is a program included in the ingress-nginx container image that can be used to show information about the nginx environment and the resulting nginx configuration, which can be helpful when debugging ingress issues in Kubernetes.
/dbg 是包含在 ingress-nginx 容器镜像中的程序,可用于展示 nginx 环境及其生成的 nginx 配置信息,这在调试 Kubernetes 入门问题时非常有帮助。

Resolution 结局
Using /dbg 使用 /dbg

This command needs to be run from inside one of the ingress-nginx pods, so first determine the pod to run it in.
这个命令需要在某个 ingress-nginx pod 内部运行,所以先确定要运行的 pod。

> kubectl get pods -n ingress-nginx NAME READY STATUS RESTARTS AGE default-http-backend-67cf578fc4-54jlz 1/1 Running 0 5d nginx-ingress-controller-56nss 1/1 Running 0 5d nginx-ingress-controller-hscfg 1/1 Running 0 4d21h nginx-ingress-controller-n4p22 1/1 Running 0 5d
> export NGINX_POD=nginx-ingress-controller-n4p22

If you are diagnosing specific connection issues, you can determine which controller is receiving the traffic by looking through the logs of each.
如果你在诊断具体的连接问题,可以通过查看每个控制器的日志来确定是哪个控制器接收了流量。

Viewing ingress-controller status
查看入口-控制器状态

/dbg general will show the count of running controllers.
/dbg general 会显示运行控制器的数量。

> kubectl exec -n ingress-nginx $NGINX_POD /dbg general { "controllerPodsCount": 3 }
Viewing backend configuration
查看后端配置

/dbg backends list will list the discovered backends:
/DBG 后端列表将列出已发现的后端:

> kubectl exec -n ingress-nginx $NGINX_POD /dbg backends list cattle-system-rancher-80 upstream-default-backend

/dbg backends get will show the configuration for the named backend:
/dbg 后端 get 会显示命名后端的配置:

> kubectl exec -n ingress-nginx $NGINX_POD /dbg backends get cattle-system-rancher-80
Viewing ingress certificate data
查看入口证书数据

/dbg certs will dump the x509 cert and key for a certificate that nginx has discovered from k8s secrets for the given hostname:
/dbg 证书会倾倒 nginx 从 k8s 秘密中发现的 x509 证书和密钥,该证书针对给定主机名:

> kubectl exec -n ingress-nginx $NGINX_POD /dbg certs get <fqdn>
Viewing dynamically generated nginx configuration
查看动态生成的 nginx 配置

/dbg conf will dump the dynamically generated nginx configuration. To view the configuration for a specific ingress hostname, you could run /dbg conf and then grep for the server_name:
/dbg conf 会导出动态生成的 nginx 配置。要查看特定入口主机名的配置,可以运行 /dbg conf,然后用 grep 获取 server_name:

> kubectl exec -n ingress-nginx $NGINX_POD /dbg conf | grep "server_name example.com" -B2 -A20
Cause 病因
Additional Information 附加信息
Environment 环境
Kubernetes environments with nginx-ingress-controller
带有 nginx-ingress-controller 的 Kubernetes 环境

nginx /dbg 是什么与如何使用

nginx /dbg并非标准 Nginx 核心的内置功能,而是Kubernetes ingress-nginx 控制器提供的专用调试工具,用于快速检查和诊断运行中的 Nginx Ingress 实例状态。它是一个命令行工具,通常位于 Ingress 容器的/dbg路径下,帮助运维人员排查路由配置、后端服务、证书等相关问题。


一、核心定位与适用场景

  • 定位:ingress-nginx 官方调试工具,用于实时检查Nginx 配置、后端服务、upstream 状态、证书信息等
  • 适用:仅适用于 Kubernetes 环境中的 ingress-nginx 控制器,不适用于独立部署的标准 Nginx
  • 用途
    • 排查路由转发异常(404/502/503 等)
    • 验证动态配置是否正确加载
    • 检查证书有效性与匹配情况
    • 查看 upstream 后端健康状态
    • 收集调试信息用于问题诊断

二、使用方法(Kubernetes 环境)

1. 进入 Ingress 容器

首先通过 kubectl 进入运行中的 ingress-nginx Pod 容器:

bash

运行

kubectl exec -it -n <命名空间> <ingress-pod-name> -- bash # 示例(默认命名空间通常为 ingress-nginx) kubectl exec -it -n ingress-nginx ingress-nginx-controller-7f98d6f5b4-2x7z9 -- bash

2. 执行 /dbg 命令

在容器内直接运行/dbg可查看所有可用子命令:

bash

运行

/dbg # 输出示例: Available Commands: backends Inspect the dynamically-loaded backends information certs Inspect certificate information config Output the full nginx configuration help Help about any command info Show information about the nginx instance server Inspect server configuration upstream Inspect upstream information

3. 常用子命令详解

表格

命令功能示例
/dbg config输出完整 Nginx 配置/dbg config
/dbg backends all查看所有动态后端服务信息(JSON 格式)/dbg backends all
/dbg certs查看所有加载的证书信息/dbg certs
/dbg upstream查看 upstream 集群状态/dbg upstream
/dbg info显示 Nginx 实例基本信息/dbg info
/dbg server查看虚拟主机配置/dbg server

4. 进阶用法

  • 过滤输出:结合 grep/jq 处理 JSON 结果

    bash

    运行

    /dbg backends all | jq '.items[] | {name: .name, service: .service}'
  • 导出配置:将完整配置保存到本地

    bash

    运行

    /dbg config > /tmp/nginx.conf # 从容器复制到本地 kubectl cp -n ingress-nginx ingress-nginx-controller-7f98d6f5b4-2x7z9:/tmp/nginx.conf ./local-nginx.conf

访问Rancher-K8S解决方案博主,企业合作伙伴 :
https://blog.csdn.net/lidw2009

http://www.jsqmd.com/news/680318/

相关文章:

  • 2026年热门的推拉门窗/大连阳光房门窗/卧室门窗厂家综合对比分析 - 品牌宣传支持者
  • 华为eNSP模拟企业网:三层交换机DHCP配置保姆级教程(含VLAN规划与排错)
  • 2026影视拍摄模特选购指南:宣传单派发、小丑魔术师、展会充场、展会兼职、展会模特礼仪、展会派发传单、展会礼仪模特选择指南 - 优质品牌商家
  • 告别付费数据源!用Python+Baostock+MySQL搭建你的免费股票数据本地库(保姆级教程)
  • 智能车竞赛节能信标改造:用ITR9909+BC517达林顿管替换霍尔传感器(附完整电路图)
  • 告别手动抄数据:5分钟学会用WebPlotDigitizer智能提取图表数据
  • 360挖出微软8年致命漏洞,10亿用户安危被改写
  • 为什么头部云厂商已强制要求Docker 27低代码标准?揭秘CNCF最新容器化准入白皮书核心条款
  • XGBClassifier默认参数里藏了哪些坑?新手必看的6个实战避雷指南
  • 141. PLEG is not healthy 问题
  • MCNP新手避坑指南:用Fmesh卡计算钴-60源剂量当量,从几何建模到结果可视化的完整流程
  • 软件测试工程师的35岁破局之道:构建技术与管理双轨制晋升体系
  • 别再死记硬背AHP公式了!用Excel+Python 5分钟搞定数学建模里的权重计算
  • 手机号逆向查询QQ号:3步高效解决方案完整指南
  • 从“完美”执念到“价值”觉醒:一位测试工程师的3000用例优化心路
  • 逆向思维学PWN:通过GDB调试实战,动态理解寄存器与栈的变化
  • Docker 27网络策略升级全貌(隔离能力提升270%?内测数据首次公开)
  • 143. Rancher 支持 Docker 吗?
  • 告别U-Net独大?手把手带你用PyTorch和MONAI复现UNETR,搞定3D医学图像分割
  • GLM-TTS流式推理体验:低延迟实时语音合成,打造交互式应用
  • 避开这些坑!ESP32-CAM驱动舵机时GPIO冲突与电源问题的实战解决
  • 智能门锁加盟哪家好?2026智能门锁加盟/智能指纹锁源头厂家/口碑品牌优选推荐 - 栗子测评
  • 从一颗1N4148说起:在老式收音机里,我是如何发现并修复温度漂移故障的
  • 2026年口碑好的气源处理/气源处理过滤减压阀优质公司推荐 - 行业平台推荐
  • 【仅限内部团队流传】:Docker daemon.json中隐藏的ai-scheduler参数(max-concurrent-builds=0竟导致LLM微调中断)
  • 2026国内动作捕捉技术公司/模拟训练方案源头厂家推荐:电磁动捕设备/电磁定位系统/电磁数据手套/光学动捕设备定制厂家 - 栗子测评
  • 深度学习 —— 损失函数
  • 2026年比较好的机制路边石/滑县路边石/透水路边石批量采购厂家推荐 - 品牌宣传支持者
  • 第二篇:《主流UI自动化工具横向对比:Selenium、Cypress、Playwright、Puppeteer》
  • AudioLDM-S音效生成质量评测:CNN与人类听觉对比实验