It’s best practice for ASP.NET Core applications to have a “real” webserver in front of them. We’ll configure NGINX for the job using Ansible. We don’t hate all best practices. ASP.NET Core applications have a built-in webserver called Kestrel. This internal webserver is not intended to serve requests directly. It must be placed behind a production quality webserver such as NGINX, IIS, etc. We chose NGINX because we have experience with it and it runs on Linux. Ansible does all the needed configuration and keeps our servers consistent and predictable.
Configure NGINX with Ansible
Everything we need can be accomplished from a single playbook. This playbook installs NGINX, configures it, copies SSL keys and enables the ASP.NET Core site:
That’s it! NGINX can now serve production traffic and reverse proxy to our ASP.NET Core application. The ASP.NET Core application is run manually from an SSH session to check that NGINX is working. Next we’ll remove this manual step by using systemd to run our ASP.NET Core application automatically.