问答

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

作者:admin 2021-06-22 我要评论

描述 网关路由后renren-fast的api失效, 如验证码 由前端发送的请求: http://localhost:88/api/captcha.jpg - 被路由为: http://localhost:8001/api/captcha.jpg ...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

描述

网关路由后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
###

github建个仓库发来看看

###

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

###

请问你解决了吗?

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • Gateway路由转发503,是路由配置问题?注

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

  • antd 想要datepicker只能选择每一年的

    antd 想要datepicker只能选择每一年的

  • echarts-曲线图封装series的类型多少能

    echarts-曲线图封装series的类型多少能

  • vscode 代码提示 如何显示代码详情

    vscode 代码提示 如何显示代码详情

腾讯云代理商
海外云服务器