Skip to content

端口配置

本文档列出 Fastdotnet 项目各服务的默认端口配置。


📋 默认端口列表

服务端口说明
后端 API18889Fastdotnet.WebApi
前端管理端18888Web/fastdotnet-admin
前端应用端18887Web/fastdotnet-app
Swagger UI18889http://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:18887

Docker 环境

Docker 部署时,可以通过 docker-compose.yml 映射不同的宿主机端口:

yaml
services:
  webapi:
    ports:
      - "18889:8080"  # 宿主机:容器
  
  admin:
    ports:
      - "18888:80"
  
  app:
    ports:
      - "18887:80"

⚠️ 注意事项

  1. 端口冲突:确保端口未被其他程序占用
  2. 防火墙:生产环境需要开放相应端口
  3. CORS 配置:修改端口后需更新 CORS 允许的来源
  4. 前端代理:前端开发环境的代理配置需要同步更新

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> /F

Linux/macOS

bash
# 查看端口占用
lsof -i :18889

# 结束占用进程
kill -9 <进程ID>

📚 相关文档

Released under the MIT License.