Load Balancing an ASP.NET Core Web App using Nginx and Docker

Host an ASP.NET Core Web API app with Nginx and Docker: Load Balancing

Changhui Xu
codeburst
Published in
6 min readJun 27, 2020

--

Following the two articles (Configure ASP.NET Core to work with proxy servers and load balancers and Host ASP.NET Core on Linux with Nginx) in Microsoft Docs, I created a demo application using Docker Compose, which orchestrates an Nginx reverse proxy server and an ASP.NET Core Web API app. The following screen recording shows the demo app.

In the demo, the web API app is replicated to four instances ( -- scale api=4), and Nginx is served as a reverse proxy for the four api services. When the client visits the https://localhost site, the four api services handle the HTTP requests in a round-robin manner, as can be seen from the console logs and the Host Name in the web page.

The complete solution is located in my GitHub repository. In this article, we will go over some implementation details.

Create an ASP.NET Core Web API Project

We first create an ASP.NET Core Web API project MyWebApi from the dotnet template. Since we will use…

--

--

Lead Application Developer. MBA. I write blogs about .NET, Angular, JavaScript/TypeScript, Docker, AWS, DDD, and many others.