ocelot 网关 根据域名区分路由
一、安装ocelot 建议项目用.net core 5
二、配置路由
{ "Routes": [ { "DownstreamPathTemplate": "/", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "127.0.0.1", "Port": 80 } ], "UpstreamPathTemplate": "/", "UpstreamHttpMethod": [ "Get","Post" ], "UpstreamHost": "www.jkcr.com:5000" } ], "GlobalConfiguration": { "BaseUrl": "http://localhost:5000" } }
UpstreamHost 这个为上油的Host,根据这个去匹配路由
官方的文档也有介绍:Routing — Ocelot 1.0.0 documentation
三、项目引用
public void ConfigureServices(IServiceCollection services) { //... services.AddOcelot(new ConfigurationBuilder().AddJsonFile("Ocelot.json", true, true).Build()); //... } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseOcelot().Wait(); }