.NET is Microsoft’s open-source, cross-platform framework for building web APIs, console applications, microservices, and more. RHEL 8 is a fully supported platform for .NET 8, and Microsoft provides a dedicated package repository that integrates cleanly with dnf. This tutorial shows you how to add the Microsoft repository, install the .NET 8 SDK and ASP.NET Core Runtime, scaffold a minimal Web API, and deploy it behind Nginx with a systemd service managing the Kestrel application server.
Prerequisites
- A RHEL 8 server or workstation with a non-root sudo user
- EPEL 8 repository enabled (
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm) - Nginx installed (
dnf install -y nginx) with firewall ports 80/443 open - At least 2 GB of free disk space for the SDK and build cache
Step 1 — Add the Microsoft Package Repository
Microsoft distributes .NET packages through its own RPM repository. Import the GPG signing key and register the repository with a single command.
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Add the packages-microsoft-prod repository file for RHEL 8:
sudo tee /etc/yum.repos.d/microsoft-prod.repo > /dev/null << 'EOF'
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/8/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
EOF
Refresh the metadata cache to confirm dnf can reach the new repository:
sudo dnf check-update
Step 2 — Install the .NET 8 SDK and Runtime
The SDK includes the runtime, CLI tools, and everything needed to build and publish applications. The ASP.NET Core Runtime is also installed explicitly so it is available for non-SDK deployments.
sudo dnf install -y dotnet-sdk-8.0 aspnetcore-runtime-8.0
Verify the installation:
dotnet --version
dotnet --list-sdks
dotnet --list-runtimes
You should see 8.0.x reported by dotnet --version.
Step 3 — Create and Run a Web API Project
Scaffold a new minimal Web API using the built-in project template.
dotnet new webapi -n MyApi
cd MyApi
Start the development server. Kestrel binds to http://localhost:5000 and https://localhost:5001 by default.
dotnet run
In another terminal, test the sample endpoint that the template generates:
curl http://localhost:5000/weatherforecast
You should receive a JSON array of weather objects. Stop the server with Ctrl+C.
Step 4 — Publish a Release Build
Publishing produces a self-contained output directory with compiled assemblies ready for deployment.
dotnet publish -c Release -o /var/www/myapi
The -c Release flag enables compiler optimisations and strips debug symbols. Set correct ownership if you plan to run the service as a dedicated user:
sudo chown -R dotnetuser:dotnetuser /var/www/myapi
Step 5 — Create a systemd Service for Kestrel
A systemd unit ensures Kestrel starts automatically and restarts on failure. Replace dotnetuser with the system account you want to run the service under.
sudo tee /etc/systemd/system/myapi.service > /dev/null << 'EOF'
[Unit]
Description=ASP.NET Core 8 Web API - MyApi
After=network.target
[Service]
Type=simple
User=dotnetuser
WorkingDirectory=/var/www/myapi
ExecStart=/usr/bin/dotnet /var/www/myapi/MyApi.dll
Restart=on-failure
RestartSec=5
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://127.0.0.1:5000
[Install]
WantedBy=multi-user.target
EOF
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable --now myapi
sudo systemctl status myapi
Step 6 — Configure Nginx as a Reverse Proxy
Place Nginx in front of Kestrel to handle TLS termination, static file caching, and connection management.
sudo tee /etc/nginx/conf.d/myapi.conf > /dev/null << 'EOF'
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
EOF
Test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Verify end-to-end connectivity:
curl http://yourdomain.com/weatherforecast
Conclusion
You have added the Microsoft package repository to RHEL 8, installed the .NET 8 SDK, scaffolded and tested an ASP.NET Core Web API, published a release build, and deployed it with a systemd service behind an Nginx reverse proxy. This setup is production-ready for internal or low-traffic services; for high availability, add a load balancer and run multiple Kestrel instances. Secure the site by obtaining a TLS certificate with Certbot and updating the Nginx server block to listen on port 443.
Next steps: How to Install Rust and Cargo on RHEL 8, How to Deploy a Ruby on Rails Application on RHEL 8, and How to Install Deno on RHEL 8.