'ASP.NET Core YARP Reverse Proxy multiple listen ports

I want to Reverse Proxy multiple ports, with YARP.

0.0.0.0:5001  =>  RemoteHost.com:7001
0.0.0.0:5002  =>  RemoteHost.com:7002
0.0.0.0:5003  =>  RemoteHost.com:7003
0.0.0.0:5004  =>  RemoteHost.com:7004

All the examples seem to map URLs, and not ports.

public class ProxyConfigProvider : IProxyConfigProvider
{

var routeConfig = new RouteConfig
{
       RouteId = "route1",
       ClusterId = "cluster1",
       Match = new RouteMatch
       {
           Path = "/api/service1/{**catch-all}"
       }
};

var clusterConfig = new ClusterConfig
  {
      Destinations = new [] = {"Address": "https://RemoteHost.com:7001"}
....

How do you set up Kestrel and YARP to do what I want?



Solution 1:[1]

You can route by port using the Hosts field

"Match": {
  "Hosts" : [ "*:5001" ]

You also need to tell kestrel to listen on those ports.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FlappySocks