How I Hosted My First ASP.NET Core API on Ubuntu
How I Hosted My First ASP.NET Core API on Ubuntu
After setting up Ubuntu Server on my old laptop, I wanted to move beyond simple experiments and host a real ASP.NET Core Web API.
This was my first experience deploying a .NET application on Linux. Along the way, I learned about publishing applications, systemd services, reverse proxies, SSL certificates, and server management.
In this article, I'll share the process I followed and the lessons I learned.
Why Ubuntu?
I chose Ubuntu Server because:
- Lightweight and stable
- Excellent support for .NET
- Easy package management
- Large community support
- Suitable for low-end hardware
My server specifications:
- Lenovo E41-15
- AMD PRO A4 Processor
- 4 GB RAM
- 500 GB HDD
- Ubuntu Server
Despite the modest hardware, it was more than enough to host my API and database.
Installing .NET on Ubuntu
The first step was installing the .NET SDK.
sudo apt update
sudo apt install -y dotnet-sdk-8.0
After installation:
dotnet --version
This confirmed that .NET was successfully installed.
Publishing the API
On my development machine, I published the application using:
dotnet publish -c Release
This generated optimized files inside:
bin/Release/net8.0/publish/
I then copied the published files to the Ubuntu server.
Running the API
To verify everything worked:
dotnet StreamOps_API.dll
The API started successfully and listened on the configured port.
I could access endpoints locally using:
curl http://localhost:5000/api/health
Creating a systemd Service
Running the application manually wasn't practical because it would stop whenever the terminal session ended.
To keep the API running automatically, I created a systemd service.
sudo nano /etc/systemd/system/streamops.service
Service file:
[Unit]
Description=StreamOps API
After=network.target
[Service]
WorkingDirectory=/opt/streamops
ExecStart=/usr/bin/dotnet /opt/streamops/StreamOps_API.dll
Restart=always
RestartSec=10
User=root
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable streamops
sudo systemctl start streamops
Check status:
sudo systemctl status streamops
This was the first time I realized how powerful Linux services are.
Configuring Nginx
Instead of exposing the application directly, I used Nginx as a reverse proxy.
Install:
sudo apt install nginx
Configuration:
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Now requests were routed through Nginx to my ASP.NET Core API.
Enabling HTTPS
To secure the API, I used Certbot.
sudo apt install certbot python3-certbot-nginx
Generate SSL:
sudo certbot --nginx
Within minutes, the API was accessible over HTTPS.
Useful Commands I Learned
Restart service:
sudo systemctl restart streamops
View logs:
journalctl -u streamops -f
Restart Nginx:
sudo systemctl restart nginx
Check listening ports:
sudo ss -tulpn
These commands became part of my daily workflow.
Challenges I Faced
Permission Issues
Initially, the service couldn't access some folders due to Linux permissions.
Firewall Configuration
I had to allow traffic through the firewall:
sudo ufw allow 80
sudo ufw allow 443
Application Crashes
Using systemd restart policies helped the API recover automatically.
Learning Linux
Coming from a Windows background, managing services and logs through the terminal took time to learn.
What I Learned
Hosting my first ASP.NET Core API taught me much more than simply deploying an application.
I learned:
- Linux server administration
- systemd service management
- Nginx reverse proxies
- SSL certificates
- Firewall configuration
- Application monitoring
- Troubleshooting production issues
These skills later helped me build larger projects such as StreamOps, where I now manage APIs, PostgreSQL databases, background services, SignalR communication, and FFmpeg-based streaming systems.
Final Thoughts
You don't need expensive cloud infrastructure to learn backend deployment.
An old laptop, Ubuntu Server, and a willingness to learn are enough to gain real-world experience.
My first self-hosted ASP.NET Core API became the foundation for many of the projects I build today.

Join the conversation