Requirements
- Digital Ocean account
- DeployHQ account
- .NET 8.0 project in a Git repository
- Domain name (optional)
1. Initial Digital Ocean Setup
- Create a Digital Ocean Droplet running
Ubuntu 22.04 LTS
- 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
- Sign up for a DeployHQ account
- Create a new project
- Connect your Git repository
- 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
- In DeployHQ project settings:
- Set the repository branch to deploy from
- Configure build commands:
dotnet restore
dotnet publish --configuration Release
- Set deployment path:
/var/www/your-app
- 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
- In DeployHQ dashboard, click "Deploy"
- Review changes
- 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
- In DeployHQ, go to "Automatic Deployments"
- Enable automatic deployments for your branch
- 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.