在 Debian 系统上“访问 Swagger UI”通常有几种常见场景,下面按最常见情况给你说明。
大多数情况是:
假设服务运行在:
http://localhost:8080
Swagger UI 常见路径:
/swagger-ui.html
/swagger-ui/
/swagger-ui/index.html
/api-docs
示例:
http://localhost:8080/swagger-ui.html
在 Debian 上:
xdg-open http://localhost:8080/swagger-ui.html
或直接使用浏览器访问。
如果 Swagger 在远程 Debian 服务器:
http://服务器IP:端口/swagger-ui.html
⚠️ 注意:
127.0.0.1检查监听:
ss -tulnp | grep 8080
如果是:
127.0.0.1:8080
外部是访问不了的。
在本机执行:
ssh -L 8080:localhost:8080 user@debian服务器IP
然后本机浏览器访问:
http://localhost:8080/swagger-ui.html
如果你想在 Debian 上自己跑一个 Swagger UI:
sudo apt update
sudo apt install -y nginx
cd /var/www
sudo git clone https://github.com/swagger-api/swagger-ui.git
sudo nano /etc/nginx/sites-available/swagger
内容示例:
server {
listen 80;
server_name _;
location / {
root /var/www/swagger-ui/dist;
index index.html;
}
}
启用:
sudo ln -s /etc/nginx/sites-available/swagger /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
访问:
http://debian的IP/
http://localhost:8000/docs
http://localhost:8080/swagger-ui.html
✅ 打不开?
0.0.0.0查看日志:
journalctl -u 服务名
如果你能告诉我:
我可以给你更精确的操作步骤。