Server configuration

What needs to be set up on a server?

There is a few things that are necessery for an application to run on a server. Previous steps built, published and copied files over but there is still some stuff left to do.

  • Firstly, we need to install in this case .Net runtime.
  • Secondly, the application needs a directory and it also needs a service file. Here is example of a directory path and service file.

"/var/www/your-app-name-here"
                                

[Unit]
Description=My .NET App
After=network.target

[Service]
WorkingDirectory=/var/www/"your-app-name-here"
ExecStart=/usr/bin/dotnet /var/www/mytestapp/published/"your-app-name-here".dll --urls=http://0.0.0.0:5000
Restart=always
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target
                                
  • Lastly, we need to run these three commands to reload, set and start our app.

sudo systemctl daemon-reexec                    # Reload systemd config
sudo systemctl enable "your-app-name-here"      # Start on boot
sudo systemctl start "your-app-name-here"       # Start it now
                                

Additional Nginx configuration

Nginx is a high-performance web server and reverse proxy server used to serve static content, manage HTTP requests, and handle load balancing. Here are a few steps to make this website use it:

  • Install Nginx

sudo apt update
sudo apt install nginx
                                
  • Create new file for your site in /etc/nginx/sites-available

server {
         listen 80;
         server_name ${{ secrets.DROPLET_HOST }};
       
         location / {
           proxy_pass         http://localhost:${{ vars.PORT }}/;
           proxy_http_version 1.1;
           proxy_set_header   Upgrade $http_upgrade;
           proxy_set_header   Connection keep-alive;
           proxy_set_header   Host $host;
           proxy_cache_bypass $http_upgrade;
           proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header   X-Forwarded-Proto $scheme;
         }
       }
                                
  • Link sites-available to sites-enabled

sudo ln -s /etc/nginx/sites-available/"file-name-here" /etc/nginx/sites-enabled/"file-name-here"
                                
  • Optionally delete default page from both above locations

sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
                                
  • Reload Nginx

sudo nginx -t
sudo systemctl reload nginx
                                

Small caveat

This is a high overview of things needed to do. There still might be some configuration left to do depending on your circumsatnce.

An unhandled error has occurred. Reload 🗙