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
这两处配置