Gateway路由转发503,是路由配置问题?注册中心问题?

发布于 2022-09-12 03:42:59 字数 3999 浏览 43 评论 0

描述

网关路由后renren-fast的api失效, 如验证码

由前端发送的请求: http://localhost:88/api/captcha.jpg -> 被路由为: http://localhost:8001/api/captcha.jpg

正确的地址应该是: http://localhost:8001/renren-fast/captcha.jpg

于是使用路径重写RewritePath filter
- RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}

前端发送请求到网关, 网关转发到具体的服务,
但是出现503错误: Unable to find instance for renren-fast

尝试

  • 查看Nacos注册中心, 存在renren-fast服务
  • 查看Nacos注册中心, 不存在gateway服务
  • 检查了路由配置, 重启服务和注册中心, 仍然503
  • renren-fast服务能够单独访问成功,但连接注册中心后一直报错:

    java.net.ConnectException: no available server
    at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:115)
    
    而且日志打印的信息nacos端口并不是我配置的8868
     [NACOS ConnectException httpPost] currentServerAddr: http://localhost:8848, err : Connection refused: connect
    
  • 重启前端项目, 除了ESlint的警告没有别的错
  • 将nacos端口和服务发现配置改回8848, 并将所有服务clean, 删除target后
  • 发现不再报nacos的错了, 但是请求还是503 T_T

小白没有经验,需要我提供什么信息请说明
求指点, 多谢

路由配置

spring:
  application:
    name: gomall-gateway
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8868
    gateway:
      discovery:
        locator:
          enabled: true
          lowerCaseServiceId: true 
          filters:
            - StripPrefix=1
      routes:
        - id: test_route
          uri: https://www.baidu.com
          predicates:
            - Query=url,baidu
        - id: qq_route
          uri: https://www.qq.com
          predicates:
            - Query=url,qq
        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}
server:
  port: 88

服务配置

spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        druid:
            driver-class-name: com.mysql.cj.jdbc.Driver
            url: jdbc:mysql://192.168.107.133:3306/gomall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
            username: root
            password: root
            initial-size: 10
            max-active: 100
            min-idle: 10
            max-wait: 60000
            pool-prepared-statements: true
            max-pool-prepared-statement-per-connection-size: 20
            time-between-eviction-runs-millis: 60000
            min-evictable-idle-time-millis: 300000
            #Oracle需要打开注释
            #validation-query: SELECT 1 FROM DUAL
            test-while-idle: true
            test-on-borrow: false
            test-on-return: false
            stat-view-servlet:
                enabled: true
                url-pattern: /druid/*
                #login-username: admin
                #login-password: admin
            filter:
                stat:
                    log-slow-sql: true
                    slow-sql-millis: 1000
                    merge-sql: false
                wall:
                    config:
                        multi-statement-allow: true
    cloud:
        nacos:
            discovery:
                server-addr: 127.0.0.1:8868
    application:
        name: renren-fast

请求信息

Request URL:  http://localhost:88/api/captcha.jpg?uuid=27080dae-dd8e-4fa9-8db4-a2e7c625a2a5
    
Request Method: GET
    
Status Code: 503 Service Unavailable

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杀手六號 2022-09-19 03:42:59

github建个仓库发来看看

云之铃。 2022-09-19 03:42:59

我也是这个问题,没有装Nacos的依赖

倾城°AllureLove 2022-09-19 03:42:59

请问你解决了吗?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文