Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple ASP.NET Core (3.1x/Latest) websites on port 80 with Kestrel

I'm using (ASP).NET Core (3.1x), C#, Blazor and Microsoft Kestrel Web-server and I'm wondering if I can run 2 or 3 different websites (domain names) on one Kestrel instance and on port 80. I would really like to use Kestrel as the only web server and not use a proxy server like nginx in front of it.

I've been googling for an answer for a while now but I can't find an answer to this question. I'm renting colocation server space where I run an Ubuntu 18.04 VPS, and I would really like to run multiple websites on this one VPS, instead of renting multiple VPS's. I am thinking about some sort of routing but I can't figure it out.

Is there any way to use Kestrel and run different websites on port 80?

Update - feb 25th 2020

I've created a Github issue about this, long story short: Use a reverse proxy server like Nginx (for Linux). Only one Kestrel process can run on port 80, and there no good way to host multiple websites with one instance.

Update - May 4th 2021

It is now possible with Microsoft's reverse proxy "YARP", which is a separate Kestrel instance. See my answer below.

like image 813
Jaap Avatar asked Feb 04 '20 10:02

Jaap


People also ask

Can we host NET Core application in Kestrel?

Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates. Kestrel supports the following scenarios: HTTPS.

Is Kestrel good for production?

Yes, Kestrel is production ready and is supported on all platforms and versions that . NET Core supports, but if your application is available on public networks Microsoft recommend that you use it with a reverse proxy: Even if a reverse proxy server isn't required, using a reverse proxy server might be a good choice.

What port does Kestrel use?

This default configuration is specified in the generated Properties/launchSettings. json file and can be overridden. If no ports are specified, Kestrel binds to http://localhost:5000 .

How do I change the port number of a .NET Core application?

In Properties-> LaunchSettings. json. Open LaunchSettings. json and change the Port Number.


1 Answers

To run multiple domains on one server on port 80 and/or 443 with Kestrel you'll need to put a reverse proxy in front of it.

Microsoft has now its own really fast reverse proxy called YARP which is actually another Kestrel instance, see: Getting Started With Yarp

To use it with TLS/HTTPS you'll need Kestrel's SNI feature, see this GitHub discussion for more info

Here's a sample appsettings.Development.json GIST how I did it.

like image 137
Jaap Avatar answered Oct 18 '22 15:10

Jaap