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

  1. server{
  2. listen 80;server_name blah.blah.com
  3. location / {
  4. proxy_pass http://localhost:6868;
  5. proxy_http_version 1.1;
  6. proxy_set_header Upgrade $http_upgrade;
  7. proxy_set_header Connection keep-alive;
  8. proxy_set_header Host $http_host;
  9. proxy_cache_bypass $http_upgrade;
  10. }
  11. }

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

  1. [Unit]
  2. Description=Blah .net core 2.0 app[Service]
  3. WorkingDirectory=/var/www/vhosts/Blah/htdocs
  4. ExecStart=/bin/bash /root/blah-start
  5. ExecStop=/bin/bash /root/blah-stop
  6. Restart=always
  7. RestartSec=10
  8. SyslogIdentifier=dotnet-example
  9. User=www-data
  10. Environment=ASPNETCORE_ENVIRONMENT=Production
  12. [Install]
  13. 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