= How can I host multiple ASP.NET websites on the same Windows Server 2019 VPS ? =

Hi,
I recently started developping in C# and .NET 6.0. I created 3 websites that run locally, and I'm now trying to find a solution to host them on a VPS. I tried Microsoft Azure but it's way too expensive

I have a Windows Server 2019 VPS provided by OVHcloud, and I managed to host one of my websites on it after many hours of research. But when I try to use the same method it doesn't work

Does anyone have any experience with hosting websites on Windows Server ?
Assuming the VPS only has one IP address, what you're looking for to do is called hosting by host headers. You create multiple domains and point them all to the same IP address. Then on the VPS you open IIS, create the additional sites, and set the bindings for each site to one of the created domains

IIS should now present the correct site for each domain

You don't need a reverse proxy at all

I remember when I wanted to host my first website - the tutorials don't set you up for using an actual web server like IIS so I was messing around all night trying to figure out the networking aspects

You don't need the default website - you create a new website under the Sites node for each site you want. On the site, Right-click > Explore. Paste your site's publish output in here

On the site, Right-click > Edit bindings > Add. Add a binding of type http, IP Address: All Unassigned (probably fine), port 80

Host name: e.g. www.example.com
Now if you own example.com, you go to your registrar and update your DNS records. You add a Type A record with the value of your server's public IPv4 address (e.g. 123.456.789.123), for the binding www.example.com, because www is probably the subdomain you want to use

When you separate websites like this, IIS routes them based on Server Name Indication - that is, www.example.com goes to one site, api.example.com can go to another. You can also use port numbers but not for normal websites that you expect to just work in a browser

Also you may want to redirect example.com to www.example.com. Your registrar should facilitate this

Make sure your firewall allows inbound port 80 requests on the machine itself, and in any admin tools from the server provider

Now it should work in a web browser. HTTPS takes a little more work and it is usually a good idea to force it either at the website level or the web server level, and then use something like win-acme-simple to get a free cert. It integrates well with IIS


Reverse proxy with caddy works like magic. But nginx is also ok. IIS on the other hand..

I recently had to deal with a customer whose IT provider refused to touch anything remotely smelling of Linux but failed badly to make the IIS reverse proxy work. So I had to try it out on my dev environment and send them a step by step guide how to do it..

Yes, Azure is expensive, you are correct, moreover if you use MSSQL server database. It all depends on your requirement. If you only host 3 sites with small traffic, you can go with shared hosting solution, you don't need to purchase VPS, it will save your cost a lot

There are many shared hosting providers that you can use, for example I'm using Asphostportal and I host .net site with them. They have affordable price and their support is excellent too. You may take a look at them

I found this great website that lets me type in what I want to do and it gives me other websites that tell me how to do it. I used "run multiple websites on one server", and this was the first response httpwoshub.com/run-multiple-websites-on-the-same-port-and-ip-address-on-iis/
I would tell you the website that I used to do the search with, but I don't want it to get overrun with people slowing it down

== Similar to this post ==
- r/dotnetAn open source 2FA client I made for Windows powered by96%432d
- r/dotnetPerformance Improvements in .NET 799%354d
- r/dotnetAsync/Await — What Happens Under The Hood92%166d
- r/dotnetBlazor in 100 Seconds89%213d
- r/dotnetIntroducing Transitive NuGet Dependencies in Visual Studio97%2123h
- r/dotnetExample of production-ready .NET Core WebApi95%294d
- r/dotnetI Created a List of Companies Hiring .NET Developers89%94d
- r/dotnetC# / Blazor Wolfenstein89%619h
- r/dotnetNumber of projects per solution93%353d
- r/dotnetLet's secure our .NET Web APIs with a Free Let's Encrypt86%68h
- r/dotnethow to implement validation in .net core 6 and entity90%335d
- r/dotnetPerformance Improvements in .NET 789%04d
- r/dotnet.NET 6.0 - default gitignore file?92%213d
- r/dotnetIntroduction to Machine Learning with C# and ML.NET84%06d
- r/dotnet"The transaction ended in the trigger. The batch has been86%126d