在 Debian 上“访问 Swagger”通常分两种场景:Swagger UI 已经部署好了,你只是不知道怎么打开;或者你在 Debian 上开发/部署了一个带 Swagger 的服务,需要配置可被访问。下面按常见情况说明。
如果是本机运行:
curl http://localhost:8080/swagger-ui.html
或浏览器访问:
http://localhost:8080/swagger-ui.html
(端口和路径取决于你的项目,常见还有 /swagger-ui/index.html)
确保:
0.0.0.0 而不是 127.0.0.1查看监听:
ss -tunlp | grep 8080
防火墙(若使用 ufw):
sudo ufw allow 8080
远程浏览器访问:
http://<debian_ip>:8080/swagger-ui.html
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.x.x</version>
</dependency>
/swagger-ui.html/swagger-ui/index.html/v3/api-docs示例:
http://localhost:8080/swagger-ui/index.html
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/;
}
然后访问:
http://your-domain.com/swagger-ui/index.html
Spring Security 放行示例:
http.authorizeHttpRequests()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll();
Swagger 不是系统包,一般:
npm install -g swagger-ui如果你能补充:
我可以给你精确的一步一步访问方式。