• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

k8s部署gateway、nacos 、app通过网关访问app出现404

武飞扬头像
青春不流名
帮助1

  1.  
    server:
  2.  
    port: 9996
  3.  
    spring:
  4.  
    security:
  5.  
    user:
  6.  
    name: admin
  7.  
    password: 123456
  8.  
    cloud:
  9.  
    gateway:
  10.  
    enabled: true
  11.  
    loadbalancer:
  12.  
    use404: true
  13.  
    discovery:
  14.  
    locator:
  15.  
    enabled: true
  16.  
    lower_case_service_id: true
  17.  
    routes:
  18.  
    - id: 百度
  19.  
    uri: https://www.百度.com
  20.  
    predicates:
  21.  
    - Path=/百度
  22.  
    filters:
  23.  
    - StripPrefix=1
  24.  
    - id: path
  25.  
    uri: http://127.0.0.1:8090
  26.  
    predicates:
  27.  
    - Path=/demo
  28.  
    filters:
  29.  
    - StripPrefix=1
  30.  
    - id: nacos
  31.  
    uri: http://10.10.10.99:30018/nacos/#/serviceManagement?dataId=&group=&appName=&namespace=&pageSize=&pageNo=
  32.  
    predicates:
  33.  
    - Path=/nacos
  34.  
    filters:
  35.  
    - StripPrefix=1
  36.  
    #设置的id是dubbo-starter-reference
  37.  
    - id: reference
  38.  
    #网关不设置上下问,服务存在上下问情况
  39.  
    #找不到lb实例,这种写法管用的 http://dubbo-starter-reference:9997,-Path设置为 - Path=/dubbo-reference/**
  40.  
    uri: lb://dubbo-starter-reference
  41.  
    predicates:
  42.  
    - Path=/reference/**
  43.  
    filters:
  44.  
    ##由于微服务dubbo-starter-reference中设置了server.servlet.context-path=/dubbo-starter-reference,要重写路径才能正常路由到该微服务
  45.  
    - RewritePath=/reference/?(?<segment>.*), /dubbo-starter-reference/$\{segment}
  46.  
    management:
  47.  
    endpoint:
  48.  
    gateway:
  49.  
    #默认是true
  50.  
    enabled: true
  51.  
    endpoints:
  52.  
    web:
  53.  
    exposure:
  54.  
    #一直存在的
  55.  
    include: "*"
  56.  
    hystrix:
  57.  
    command:
  58.  
    default:
  59.  
    execution:
  60.  
    isolation:
  61.  
    strategy: SEMAPHORE
  62.  
    thread:
  63.  
    timeoutInMilliseconds: 3000
  64.  
    shareSecurityContext: true
学新通

上面是网关的简单配置,使用http://dubbo-starter-reference:9997可以访问成功

进入gateway的pod容器,连接dubbo-starter-reference实例正常,

将uri: lb://dubbo-starter-reference,访问接口出现404的错误。

描述:pom.xml描述,配置了actuator,并且application.yaml中设置

学新通

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.  
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.  
    <modelVersion>4.0.0</modelVersion>
  5.  
    <parent>
  6.  
    <groupId>org.springframework.boot</groupId>
  7.  
    <artifactId>spring-boot-starter-parent</artifactId>
  8.  
    <version>2.6.3</version>
  9.  
    <relativePath/>
  10.  
    </parent>
  11.  
    <artifactId>gateway-gateway</artifactId>
  12.  
    <name>gateway-gateway</name>
  13.  
    <version>0.0.1-SNAPSHOT</version>
  14.  
    <properties>
  15.  
    <swagger.version>2.9.2</swagger.version>
  16.  
    </properties>
  17.  
    <dependencies>
  18.  
    <dependency>
  19.  
    <groupId>cn.hutool</groupId>
  20.  
    <artifactId>hutool-all</artifactId>
  21.  
    <version>5.8.6</version>
  22.  
    </dependency>
  23.  
    <dependency>
  24.  
    <groupId>com.alibaba.cloud</groupId>
  25.  
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
  26.  
    <version>2021.0.1.0</version>
  27.  
    </dependency>
  28.  
    <dependency>
  29.  
    <groupId>com.alibaba.cloud</groupId>
  30.  
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
  31.  
    <version>2021.0.1.0</version>
  32.  
    </dependency>
  33.  
    &
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggccah
系列文章
更多 icon
同类精品
更多 icon
继续加载