温馨提示×

怎么调试debian swagger

小樊
41
2026-09-07 18:19:07
栏目: 智能运维

在 Debian 上“调试 Swagger”通常分几种情况,你指的是哪一种会影响具体做法。下面我按最常见场景给你一套实用思路,你可以对号入座。


一、你跑的是 Swagger UI(前端页面打不开 / 空白)

1. 先看服务是否真的在监听

sudo netstat -tlnp | grep <端口>
# 或
ss -tlnp | grep <端口>

Swagger UI 常见端口:

  • 8080 / 8000 / 3000 / 9000

2. 看 Web 服务器日志

如果是 Nginx:

sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log

如果是 Apache:

sudo tail -f /var/log/apache2/error.log

3. 浏览器端调试(最重要)

  • F12 → Console
  • 看是否有:
    • CORS 错误
    • 404 加载 swagger.json
    • JS 报错

二、你是后端(Spring / Flask / Node)暴露 Swagger

Spring Boot(最常见)

确认:

springdoc:
  swagger-ui:
    enabled: true

访问:

http://<ip>:8080/swagger-ui.html

/v3/api-docs

调试命令:

journalctl -u your-service -f

Flask (Flasgger / apispec)

app.config['SWAGGER'] = {'title': 'API'}
Swagger(app)

访问:

http://localhost:5000/apidocs/

三、你是“Swagger 文档不显示接口”

常见原因:

  1. 注解没加(@Operation / @Api
  2. 接口被 security 拦截
  3. 扫描包路径不对

调试方法:

curl http://localhost:8080/v3/api-docs

如果 JSON 是空的 → 后端问题
如果 JSON 有但 UI 空 → 前端/CORS 问题


四、Debian 特有的坑

防火墙

sudo ufw status
sudo iptables -L

SELinux(Debian 一般不默认开)

getenforce

时间 / 证书问题(HTTPS Swagger)

date
openssl x509 -in cert.pem -text -noout

五、最小调试清单(建议照做)

  1. curl http://localhost:端口/v3/api-docs
  2. 看后端日志
  3. 看 Nginx / Apache 日志
  4. 浏览器 F12

如果你愿意,可以告诉我:

  • 你用的是 Spring / Flask / Node / 其他
  • Swagger 是 UI 打不开 还是 接口不显示
  • Debian 版本(cat /etc/os-release

我可以直接给你针对你环境的调试命令

0