Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can two Kestrel processes listen on different URLs in the same domain?

Let's say I have two apps called "a"and "b". How can I get them to both run at the same time on the same domain under different virtual directories?

Identity should listen on http://localhost:8080/a/

var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseUrls($"http://*:8080/a/")
    .UseStartup<Startup>()
    .Build();
host.Run();

Userprofiles should listen on http://localhost:8080/userprofiles/

var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseUrls($"http://*:8080/b/")
    .UseStartup<Startup>()
    .Build();
host.Run();

The apps run individually but when I start them both at the same time I get this error

crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http:/ /*:8080/userprofiles: address already in use. ---> System.AggregateException: One or more errors occurred. 
(Error -4091 EADDRINUSE address already in use) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4091 EADDRINUSE address already in use
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.ThrowError(Int32 statusCode)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_getsockname(UvTcpHandle handle, SockAddr& addr, Int32& namelen)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.GetSockIPEndPoint()
like image 612
ddcc3432 Avatar asked Oct 31 '25 06:10

ddcc3432


1 Answers

Kestrel can't share ports natively. You can run it behind IIS and do this, or you can use WebListener instead.

like image 195
Tratcher Avatar answered Nov 02 '25 22:11

Tratcher