Header

Deploying .NET Applications with DeployHQ on Digital Ocean

Devops & Infrastructure, Tips & Tricks, and Tutorials

Post Image

Requirements

  • Digital Ocean account
  • DeployHQ account
  • .NET 8.0 project in a Git repository
  • Domain name (optional)

1. Initial Digital Ocean Setup

  1. Create a Digital Ocean Droplet running Ubuntu 22.04 LTS
  2. Install .NET 8.0 SDK and runtime using:
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-8.0 aspnetcore-runtime-8.0
dotnet --version

Before we can run the application, we have to do some configuration in our code. First, open the project solution using Visual Studio on your computer.

Configure launchSettings.json

The launchSettings.json the file will look like this:

{  
  "profiles": {  
    "**PROJECT_NAME**": { // REPLACE PROJECT_NAME WITH YOU ACTUAL PROJECT NAME  
      "commandName": "Project",  
      "dotnetRunMessages": true,  
      "launchBrowser": true,  
      "applicationUrl": "http://localhost:5000",  
      "environmentVariables": {  
        "ASPNETCORE_ENVIRONMENT": "Development"  
      }  
    }  
  }  
}

Remove Https Redirection Middleware

We have to remove the UseHttpsRedirection() middleware because we will use NGINX to handle the https redirection. Open the Program.cs file and make sure there are no app.UseHttpsRedirection().

We can add app.UseForwardedHeaders() middleware as well since we are using NGINX as a reverse proxy.

Clone the Project Repository

We have to install Git in our Droplet first. To do that, run the command below:

sudo apt-get install git

After Git is installed, navigate to the /home directory and clone the project.

cd /home  
git clone "**PROJECT_GIT_URL**"

If you are using GitHub, you must use your email address and personal access token for authentication.

Once the clone is done, navigate to the project directory and run the dotnet build command to ensure the application is buildable.

cd /home/**PROJECT_NAME**  
dotnet build

If you don’t want to use Git to clone the project, you can use SFTP over SSH to copy over all the files, as explained here.

2. Configure DeployHQ

  1. Sign up for a DeployHQ account
  2. Create a new project
  3. Connect your Git repository
  4. Add your Digital Ocean server:
    • Select "Servers" and click "New Server"
    • Choose "Production" environment
    • Enter server details including IP address
    • Use SSH key authentication (recommended) or password

3. Configure Deployment Settings

  1. In DeployHQ project settings:
  2. Set the repository branch to deploy from
  3. Configure build commands:
dotnet restore
dotnet publish --configuration Release
  1. Set deployment path: /var/www/your-app
  2. Configure deployment commands:
systemctl restart your-app

4. Create Service File

On your Digital Ocean droplet:

1- Create a service file:

sudo nano /etc/systemd/system/your-app.service

2- Add configuration:

[Unit]
Description=Your .NET App

[Service]
WorkingDirectory=/var/www/your-app/
ExecStart=/usr/bin/dotnet /var/www/your-app/your-app.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

5. Configure NGINX

1- Install NGINX:

sudo apt-get install nginx

2- Create NGINX configuration:

sudo nano /etc/nginx/sites-available/your-app

3- Add configuration:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:5000;
        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;
    }
}

4- Enable the site:

sudo ln -s /etc/nginx/sites-available/your-app /etc/nginx/sites-enabled/

6. Deploy with DeployHQ

  1. In DeployHQ dashboard, click "Deploy"
  2. Review changes
  3. Confirm deployment

7. SSL Configuration (Optional)

1- Install Certbot:

sudo apt-get install certbot python3-certbot-nginx

2- Generate certificate:

sudo certbot --nginx -d your-domain.com

Automatic Deployments

  1. In DeployHQ, go to "Automatic Deployments"
  2. Enable automatic deployments for your branch
  3. Configure Webhook in your Git repository

Now your .NET application will automatically deploy when you push changes to your repository.

Monitoring Deployments

  • View deployment logs in DeployHQ dashboard
  • Check application status:
sudo systemctl status your-app
  • Monitor NGINX:
sudo nginx -t
sudo systemctl status nginx

This setup provides automated deployments with zero-downtime updates and proper service management through DeployHQ.

A little bit about the author

Facundo | CTO | DeployHQ | Continuous Delivery & Software Engineering Leadership - As CTO at DeployHQ, Facundo leads the software engineering team, driving innovation in continuous delivery. Outside of work, he enjoys cycling and nature, accompanied by Bono 🐶.

Tree

Proudly powered by Katapult. Running on 100% renewable energy.