- Published on
how to deploy a dotnet service on low budget ?
- Authors
- Name
- Emin Vergil
- @eminvergil
Target Audience
I've aimed this article at people who want to learn about deployment of dotnet applications on low budget
Learning Objectives
After completing this article, you will know how to do the following:
- Register dotnet application as systemd service in linux
- Use a simple reverse proxy
How can we deploy our dotnet applications on a low budget ?
It's easy to use a cloud provider with built-in solutions for application deployment, but for hobby projects or non-profit projects, the costs can quickly add up. By managing your own deployments, you have the opportunity to keep your tech stack streamlined and efficient, avoiding unnecessary complexity. This approach not only saves money but also gives you full control over your environment, allowing for more customized and optimized solutions tailored to your project's specific needs.
My approach (step by step)
Let's assume that you will be hosting a dotnet application as a hobby project. Here is how i would do it.
Steps:
1 - Buy a 4$ VPS (linux)
2 - Create a systemd service for dotnet
3 - Create a reverse proxy
4 - Buy a domain
5 - Setup cloudflare
And that's it really.
Now i will give examples for steps 2 and 3. For other steps it is self explanotory so you can do it yourself too.
Creating a systemd service for our dotnet
To register our service to linux service we need to create a systemd service file.
Take the following steps to create systemd service file:
1 - type following command to linux terminal
- vi /etc/systemd/system/customer.service
2 - put the following content in it
[Unit]
Description=Customer API
[Service]
WorkingDirectory=/opt/app/customer
ExecStart=/usr/local/bin/dotnet /opt/app/customer/Customer.API.dll --urls "https://0.0.0.0:5251"
KillSignal=SIGINT
SyslogIdentifier=customer
User=root
Environment=ASPNETCORE_ENVIRONMENT=Development
[Install]
WantedBy=multi-user.target
3 - sudo systemctl daemon-reload
- You have to do this whenever any of the service files change at all so that
system
picks up the new info.
4 - sudo systemctl start customer
5 - sudo systemctl status customer
- this command shows the status of a service.
Reverse proxy
For this blog i will use Caddy server but you can use anything you are familiar with.
To download caddy on your machine you can check out here
Configuration
Create a Caddyfile to configure Caddy to serve your .NET application.
Create a Caddyfile:
sudo nano /etc/caddy/Caddyfile
Add the following configuration to your Caddyfile:
yourdomain.com { reverse_proxy localhost:5251 }
Replace yourdomain.com
with your actual domain name and localhost:5251
with the port where your .NET application is running.
3.Start caddy server
sudo systemctl enable caddy
sudo systemctl start caddy