端口配置
本文档列出 Fastdotnet 项目各服务的默认端口配置。
📋 默认端口列表
| 服务 | 端口 | 说明 |
|---|---|---|
| 后端 API | 18889 | Fastdotnet.WebApi |
| 前端管理端 | 18888 | Web/fastdotnet-admin |
| 前端应用端 | 18887 | Web/fastdotnet-app |
| Swagger UI | 18889 | http://localhost:18889/swagger |
🔧 修改端口配置
后端端口修改
编辑 backend/Fastdotnet.WebApi/Properties/launchSettings.json:
json
{
"profiles": {
"Fastdotnet.WebApi": {
"applicationUrl": "http://localhost:18889"
}
}
}或在命令行指定:
bash
dotnet run --urls=http://localhost:自定义端口前端管理端端口修改
编辑 Web/fastdotnet-admin/vite.config.ts:
typescript
export default defineConfig({
server: {
port: 18888, // 修改为自定义端口
}
})前端应用端端口修改
编辑 Web/fastdotnet-app/vite.config.ts:
typescript
export default defineConfig({
server: {
port: 18887, // 修改为自定义端口
}
})🌐 访问地址汇总
开发环境
后端 API: http://localhost:18889
Swagger UI: http://localhost:18889/swagger
健康检查: http://localhost:18889/health
前端管理端: http://localhost:18888
前端应用端: http://localhost:18887Docker 环境
Docker 部署时,可以通过 docker-compose.yml 映射不同的宿主机端口:
yaml
services:
webapi:
ports:
- "18889:8080" # 宿主机:容器
admin:
ports:
- "18888:80"
app:
ports:
- "18887:80"⚠️ 注意事项
- 端口冲突:确保端口未被其他程序占用
- 防火墙:生产环境需要开放相应端口
- CORS 配置:修改端口后需更新 CORS 允许的来源
- 前端代理:前端开发环境的代理配置需要同步更新
CORS 配置示例
在 appsettings.json 中:
json
{
"CorsSettings": {
"AllowedOrigins": [
"http://localhost:18888",
"http://localhost:18887"
]
}
}前端代理配置
在 Web/fastdotnet-admin/vite.config.ts 中:
typescript
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:18889',
changeOrigin: true
}
}
}
})🔍 端口占用检查
Windows
bash
# 查看端口占用
netstat -ano | findstr :18889
# 结束占用进程
taskkill /PID <进程ID> /FLinux/macOS
bash
# 查看端口占用
lsof -i :18889
# 结束占用进程
kill -9 <进程ID>