在 Debian 上“调试 Swagger”通常分几种场景,我先按最常见的几种情况给你说明,你对照自己的情况选即可。
systemctl status your-service
# 或
ps aux | grep your-app
ss -lntp | grep 8080
# 或
netstat -lntp | grep 8080
curl http://localhost:8080/swagger-ui.html
curl http://localhost:8080/v3/api-docs
如果
curl能返回 JSON,但浏览器空白,基本是前端/CDN/反向代理问题
java -jar app.jar --debug
或 application.yml:
logging:
level:
springfox: DEBUG
io.swagger: DEBUG
@Configuration
@EnableSwagger2 // 或 @EnableOpenApi
public class SwaggerConfig {}
常见误区:
springdoc-openapispringfoxiptables -L
ufw status
常见错误配置:
location /swagger-ui.html {
proxy_pass http://127.0.0.1:8080;
}
✅ 正确做法:
location /swagger-ui/ {
proxy_pass http://127.0.0.1:8080/swagger-ui/;
}
location /v3/api-docs/ {
proxy_pass http://127.0.0.1:8080/v3/api-docs/;
}
查看 Nginx 错误:
tail -f /var/log/nginx/error.log
@Override
protected void configure(HttpSecurity http) {
http
.authorizeRequests()
.antMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll();
}
server:
servlet:
context-path: /api
访问地址变为:
/api/swagger-ui.html
# 查看进程
ps aux | grep java
# 查看端口
ss -lntp
# 查看日志
journalctl -u your-service -f
# 抓包(高级)
tcpdump -i lo port 8080
你可以补充以下信息之一:
我可以直接给你对应配置文件示例。