gateway使本地相對路徑和網關相對路徑保持一致的路由配置

gateway網關端口號爲8051,本地項目端口號爲8055,

實現效果:

      本地路徑localhos:8055/test-demo/login

      網關路徑192.168.11.55:8051/test-demo/login

都能訪問到該接口

關鍵配置:

gateway:

server:
  port: 8051
  tomcat:
    uri-encoding: UTF-8
  session:
    timeout: 6000

eureka:
  client:
    enabled: true
    registerWithEureka: true
    serviceUrl:
      defaultZone: http://192.168.11.55:8050/eureka/
    fetch-registry: true
    instance:
      leaseRenewalIntervalInSeconds: 5
      leaseExpirationDurationInSeconds: 5
      preferIpAddress: true

ribbon:
  ReadTimeout: 60000
  ConnectTimeout: 60000
  eureka:
    enabled: true  
      
zuul:
#  addProxyHeaders: true
  sensitiveHeaders: 
  addHostHeader: true
  routes:
    demo-test:
      path: /demo-test/**
      stripPrefix: false
      serviceId: demo-test  
    
#hystrix.command.default.execution.timeout.enabled: false

spring:
  cloud:
    loadbalancer:
      retry:
        enabled: false
  application:
    name: demo-gateway

test-demo配置

server:
  port: 8055
  servlet.contextPath: /nari-login   #關鍵處和zuul裏面的配置相呼應

eureka:
  client:
    enabled: true
    serviceUrl:
      defaultZone: http://192.168.11.55:8050/eureka/
  instance:
    preferIpAddress: true
    ipAddress: 192.168.11.56    #此處針對有多個網關的電腦,指定某個IP的配置
    leaseRenewalIntervalInSeconds: 5
    leaseExpirationDurationInSeconds: 5
    instance-id: ${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}

spring:
  cloud:
    loadbalancer:
      retry:
        enabled: false
  application:
    name: nari-login

重點爲:servlet.contextPath: /nari-login   #關鍵處和zuul裏面的配置相呼應

和  routes:
    demo-test:
      path: /demo-test/**
      stripPrefix: false
      serviceId: demo-test  

這兩處配置

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章