server: port: 8080 spring: application: name: gateway-service # 配置中心 cloud: nacos: discovery: server-addr: ${NACOS_SERVER_ADDR:localhost:8848} namespace: dev group: DEFAULT_GROUP config: server-addr: ${NACOS_SERVER_ADDR:localhost:8848} file-extension: yml namespace: dev group: DEFAULT_GROUP # Gateway 路由配置 gateway: # 服务发现路由(自动路由) discovery: locator: enabled: false # 关闭自动路由,使用手动配置 # 手动配置路由 routes: # ==================== 认证服务路由 ==================== - id: auth-service uri: lb://auth-service predicates: - Path=/auth/** filters: - StripPrefix=1 - name: RequestRateLimiter args: redis-rate-limiter.replenishRate: 100 redis-rate-limiter.burstCapacity: 200 # ==================== 系统服务路由 ==================== - id: system-service uri: lb://system-service predicates: - Path=/system/** filters: - StripPrefix=1 # ==================== 日志服务路由 ==================== - id: log-service uri: lb://log-service predicates: - Path=/log/** filters: - StripPrefix=1 # ==================== 文件服务路由 ==================== - id: file-service uri: lb://file-service predicates: - Path=/file/** filters: - StripPrefix=1 # 全局跨域配置 globalcors: cors-configurations: '[/**]': allowedOriginPatterns: "*" allowedMethods: - GET - POST - PUT - DELETE - OPTIONS allowedHeaders: "*" allowCredentials: true maxAge: 3600 # Redis 配置(用于限流、缓存) data: redis: host: ${REDIS_HOST:localhost} port: ${REDIS_PORT:6379} database: 0 timeout: 5000ms lettuce: pool: max-active: 20 max-wait: -1ms max-idle: 10 min-idle: 5 # 认证配置 auth: enabled: true token-header: Authorization token-prefix: "Bearer " # 认证接口白名单(login/logout/captcha/refresh) auth-paths: - /auth/login - /auth/logout - /auth/captcha - /auth/refresh # 通用白名单(Swagger、健康检查等) whitelist: - /actuator/** - /v3/api-docs/** - /swagger-ui/** - /swagger-resources/** - /webjars/** - /doc.html - /favicon.ico - /error # Actuator 监控端点 management: endpoints: web: exposure: include: health,info,gateway endpoint: health: show-details: always # 日志配置 logging: level: org.springframework.cloud.gateway: DEBUG org.xyzh.gateway: DEBUG pattern: console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"