I decided to move my basic gym management application from my local Linux machine to a Digital Ocean droplet running .net core.

The process is not hard and I had the application running in under an hour. The key components of completing this task are

  1. Install .net core binaries onto the server
  2. Normal website stuff e.g. site user account, ftp or some other means of access
  3. Configure nginx to act as a reverse proxy for this site
  4. Setup a systemd profile to start and stop the application when needed.

Installing the .net core binaries

You will need to refer to the correct package for your distribution but the root of the packages are at http://packages.microsoft.com

Setup the website

Here’s where you do what you normally do to configure a site i.e. setup a directory for housing the site , creating a user for the site and setting the relevant permissions.

This has nothing to do with nginx at this point apart from setting the user group to the standard nginx one – usually www-data

Configure Nginx

The actual config for nginx is very small as you are simply configuring it to act as a reverse proxy.

Each request will be proxied to kestrel which will spit back the result to nginx to display.

Each dotnet core site will need to use it’s own internal port for proxying the connection to kestrel and kestrel will need to be listening on the same port

Below is the template I’m currently using

server{

listen 80;server_name blah.blah.com
location / {
proxy_pass http://localhost:6868;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;

}
}

Setup systemd

systemd is the replacement for the init system and in basic terms handles starting, stopping and restarting daemons.

The basic template I use is below

[Unit]
Description=Blah .net core 2.0 app[Service]
WorkingDirectory=/var/www/vhosts/Blah/htdocs
ExecStart=/bin/bash /root/blah-start
ExecStop=/bin/bash /root/blah-stop
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi.user.target

The start and stop script will depend on the application but in my case it starts/stops a docker instance running MSSQL server