在 Debian 上排查 Swagger(OpenAPI)相关故障,通常可以按「服务是否起来 → 接口是否暴露 → Swagger 配置是否正确 → 网络/权限问题」这个思路来。下面按常见场景给你一个排查清单。
systemctl status your-service
# 或
ps aux | grep your-app
如果是 Docker:
docker ps
docker logs <container_id>
ss -lntp | grep 8080
# 或
netstat -lntp | grep 8080
常见路径:
/swagger-ui.html 或 /swagger-ui/index.html/docs/api-docscurl -i http://localhost:8080/swagger-ui.html
如果返回:
404 → Swagger 未启用或路径不对403 → 权限/安全配置问题500 → 后端异常spring:
profiles:
active: dev
springdoc:
api-docs:
enabled: true
swagger-ui:
enabled: true
或旧版:
@EnableSwagger2
常见坑:
spring.profiles.active=prod 时 Swagger 被禁用/swagger-ui/**Spring Security 示例:
.antMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
from fastapi import FastAPI
from fastapi.openapi.docs import get_swagger_ui_html
app = FastAPI(docs_url="/docs")
排查:
curl http://localhost:8000/openapi.json
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
确认:
curl http://localhost:3000/api-docs
journalctl -u your-service -f
# 或
tail -f logs/app.log
重点看:
Failed to load API definitionUnable to infer base url原因:
X-ForwardedNginx 示例:
location /swagger-ui/ {
proxy_pass http://backend/;
}
原因:
ufw status
iptables -L
curl http://localhost:端口/swagger-ui.html
curl http://localhost:端口/v3/api-docs
journalctl -u 服务名 -n 100
ss -lntp
如果你能告诉我:
我可以直接帮你定位到具体配置。