在 Debian 上“配 Swagger”通常有几种常见场景,我先按最常见的情况说明,你再告诉我你具体用的是哪种技术栈,我可以给更精确的命令。
swagger-ui 静态页面下面分别说。
sudo apt update
sudo apt install -y curl wget gnupg
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
启动后浏览器打开:
http://localhost:8080/swagger-ui.html
✅ 不需要额外配置
sudo apt install -y nodejs npm
npm init -y
npm install express swagger-ui-express yamljs
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const swaggerDocument = YAML.load('./swagger.yaml');
const app = express();
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(3000);
访问:
http://localhost:3000/api-docs
sudo apt install -y nginx
sudo mkdir -p /var/www/swagger
cd /var/www/swagger
wget https://github.com/swagger-api/swagger-ui/archive/refs/tags/v5.17.14.zip
unzip v5.17.14.zip
配置 Nginx:
server {
listen 80;
root /var/www/swagger/swagger-ui-5.17.14/dist;
index index.html;
}
pip install fastapi uvicorn
自动可用:
http://localhost:8000/docs
你可以告诉我:
我可以直接给你可复制的完整配置。