Skip to content

Host an ASP.NET Core App with Nginx and Docker: SSL and Load Balancing

License

Notifications You must be signed in to change notification settings

dotnet-labs/NginxLoadBalancer

Repository files navigation

Host an ASP.NET Core App with Nginx and Docker: SSL and Load Balancing

Buy Me a Coffee at ko-fi.com

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.

load balancing

Load Balancing

docker-compose build
docker-compose up --scale api=4 --build
docker-compose up

SSL

Generate an OpenSSL certificate

On Windows, if you have Git for Windows installed, then you can use the openssl command directly. Otherwise, the official page: OpenSSL.Wiki: Binaries contains useful URLs for downloading and installation guides.

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -passin pass:YourSecurePassword

This command will generate two files: localhost.crt and localhost.key.

License

Feel free to use the code in this repository as it is under MIT license.

Buy Me a Coffee at ko-fi.com