温馨提示×

debian swagger怎么排查错误

小樊
34
2026-09-04 19:38:44
栏目: 智能运维

在 Debian 上排查 Swagger(OpenAPI)相关错误,通常要结合你用的具体技术栈(Swagger UI、Springfox、springdoc-openapi、FastAPI、Node 等)。下面按通用排查思路 + 常见场景来说明。


一、先明确你用的是哪种 Swagger

在 Debian 上常见有:

  1. Swagger UI(静态页面)
  2. Spring Boot + Springfox / springdoc-openapi
  3. Python(FastAPI / Flask + swagger)
  4. Node.js(Express + swagger-ui-express)

不同场景排查重点不同。


二、通用排查步骤(必做)

1. 看日志(最重要)

journalctl -u your-service -f
# 或
tail -f /var/log/your-app.log

重点关注:

  • 404 / 500
  • JSON 解析失败
  • CORS 错误
  • Bean / 路由加载失败

2. 确认 Swagger 地址是否可访问

curl -I http://localhost:8080/swagger-ui.html
curl -I http://localhost:8080/v3/api-docs
  • 404 → 路由没加载
  • 500 → 后端异常
  • 空白页 → 前端资源问题

3. 浏览器开发者工具(F12)

看:

  • Console 报错
  • Network 中 /v3/api-docs 是否 200
  • CORS 红字错误

三、常见场景与解决办法

✅ Spring Boot(springdoc-openapi)

依赖

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>

常见错误

  • 访问 /swagger-ui.html 404
    → 用 /swagger-ui/index.html

  • 空白页
    → 检查:

    springdoc.api-docs.path=/v3/api-docs
    springdoc.swagger-ui.path=/swagger-ui.html
    
  • 启动报错 Failed to load API definition → 注解写错(@Schema、@Operation)


✅ Springfox(旧)

⚠️ Springfox 已不维护,常见问题:

  • Spring Boot 2.6+ 路由冲突
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

✅ Python(FastAPI)

uvicorn main:app --reload

访问:

/docs
/openapi.json

错误排查:

  • 500 → 路由函数异常
  • 空白 → 端口/反向代理问题

✅ Node.js

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(spec));

常见错误:

  • JSON 格式错误
  • YAML 缩进错误

四、Debian 特有注意事项

  1. 防火墙
ufw status
  1. 反向代理(Nginx)
location /swagger-ui/ {
  proxy_pass http://127.0.0.1:8080;
}
  1. SELinux(少见但有可能)
getenforce

五、快速自检清单

  • [ ] 服务是否启动
  • [ ] 日志有无异常
  • [ ] /v3/api-docs 是否返回 JSON
  • [ ] 浏览器是否 CORS 报错
  • [ ] Nginx / 防火墙是否拦截

如果你能告诉我:

  • Debian 版本
  • 使用的语言 / 框架
  • 具体报错信息或截图

我可以直接帮你定位到具体原因和修复命令

0