Reverse proxy 如何使用netflix zuul转发到不同的路径?
我正在使用嵌入spring boot 1.5.x应用程序的netflix zuul。 zuul背后是一些微服务。这些微服务在/public/**下公开公共端点 现在我想通过zuul api网关公开这些公共端点,但从最终的api网关url中去掉“/public” 来自外部的示例(预期)(通过zuul api网关请求): Zuul应将此请求转发至(url中有/public): 如果不在zuul配置中使用url参数,如何实现此。我希望使用serviceId参数依赖内部客户端负载平衡。我想不出来 如果这不是一个好模式,我应该将我的微服务分为Web服务和核心服务吗?这样只有Web服务才能通过Zuul安装/访问 此配置工作正常,但它使用url参数而不是serviceId:Reverse proxy 如何使用netflix zuul转发到不同的路径?,reverse-proxy,http-proxy,netflix-zuul,spring-cloud-netflix,Reverse Proxy,Http Proxy,Netflix Zuul,Spring Cloud Netflix,我正在使用嵌入spring boot 1.5.x应用程序的netflix zuul。 zuul背后是一些微服务。这些微服务在/public/**下公开公共端点 现在我想通过zuul api网关公开这些公共端点,但从最终的api网关url中去掉“/public” 来自外部的示例(预期)(通过zuul api网关请求): Zuul应将此请求转发至(url中有/public): 如果不在zuul配置中使用url参数,如何实现此。我希望使用serviceId参数依赖内部客户端负载平衡。我想不出来 如果这
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
url: http://custom-service:51022/public
sensitiveHeaders:
您需要通过Spring Cloud Netflix进行服务发现,请检查并 设置之后,在zuul应用程序中启用zuul代理和发现客户端
@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class ZuulProxyApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulProxyApplication.class, args);
}
}
比:
Zuul应用程序不需要向Eureka注册,它应该获取注册表
你可以说:
zuul:
routes:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
如果要为一个服务定义多个路由,请执行以下操作:
zuul:
routes:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
custom-service:
path: /second_path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
如何使用application.properties进行相同的配置
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=true
zuul:
routes:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
zuul:
routes:
custom-service:
path: /path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId
custom-service:
path: /second_path/to/service/endpoint/**
stripPrefix: false
serviceId: customServiceId