.NET 8 is the current Long-Term Support release of Microsoft’s open-source runtime and is fully supported on RHEL 9 through Microsoft’s official package repository. ASP.NET Core applications run as self-contained processes, which makes them easy to containerise or proxy behind Nginx for production workloads. This tutorial walks through adding the Microsoft repository, installing the .NET 8 SDK, creating and publishing an ASP.NET Core Web API, managing it with systemd, and placing Nginx in front as a reverse proxy.
Prerequisites
- RHEL 9 server with a user that has
sudoprivileges - Active internet connection to reach Microsoft’s package CDN
- Nginx installed or ready to be installed (
dnf install -y nginx) - Ports 80 and 5000 open in the local firewall
Step 1 — Add the Microsoft Package Repository
Microsoft provides a signed RPM repository for RHEL 9. Import the GPG key and configure the repo before installing any packages.
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo tee /etc/yum.repos.d/microsoft-prod.repo <<'EOF'
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/9/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
EOF
sudo dnf check-update
Step 2 — Install the .NET 8 SDK and ASP.NET Core Runtime
The SDK is needed on the build machine; the ASP.NET Core runtime is what you install on servers that only run pre-published applications.
sudo dnf install -y dotnet-sdk-8.0 aspnetcore-runtime-8.0
dotnet --version
# 8.0.x
dotnet --list-sdks
dotnet --list-runtimes
Step 3 — Create and Run a Sample Web API
The dotnet new scaffolding command generates a minimal ASP.NET Core Web API with a sample weather-forecast endpoint.
cd ~
dotnet new webapi -n MyApi --no-https
cd MyApi
# Start the development server — listens on http://localhost:5000 by default
dotnet run &
# Test the API
curl http://localhost:5000/weatherforecast | python3 -m json.tool
# Stop the background process when done
kill %1
Step 4 — Publish a Release Build
The publish command compiles the application and copies all dependencies to a single output directory ready for deployment.
cd ~/MyApi
dotnet publish -c Release -o /var/www/myapi
ls /var/www/myapi/
Create a dedicated system user to run the application with least-privilege permissions:
sudo useradd -r -s /sbin/nologin dotnetapp
sudo chown -R dotnetapp:dotnetapp /var/www/myapi
Step 5 — Create a systemd Service
Register the application as a systemd service so it starts on boot and restarts automatically if the process crashes.
sudo tee /etc/systemd/system/myapi.service <<'EOF'
[Unit]
Description=My ASP.NET Core Web API
After=network.target
[Service]
Type=simple
User=dotnetapp
WorkingDirectory=/var/www/myapi
ExecStart=/usr/bin/dotnet /var/www/myapi/MyApi.dll
Restart=on-failure
RestartSec=5
KillSignal=SIGTERM
SyslogIdentifier=myapi
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://localhost:5000
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now myapi.service
sudo systemctl status myapi.service
Step 6 — Configure Nginx as a Reverse Proxy
Nginx handles TLS termination, keeps the ASP.NET Core port off the public internet, and allows multiple applications to share port 80/443.
sudo dnf install -y nginx
sudo tee /etc/nginx/conf.d/myapi.conf <<'EOF'
server {
listen 80;
server_name yourdomain.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_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
sudo nginx -t
sudo systemctl enable --now nginx
# Open port 80 in the firewall
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
curl http://localhost/weatherforecast
Conclusion
You have added the Microsoft package repository to RHEL 9, installed the .NET 8 SDK and ASP.NET Core runtime, scaffolded and published a Web API to /var/www/myapi, registered it as a systemd service running under a least-privilege account, and configured Nginx as a reverse proxy that forwards public HTTP traffic to the .NET process.
Next steps: How to Install and Use Podman with systemd Socket Activation on RHEL 9, How to Install Go and Build CLI Tools on RHEL 9, and How to Install Java and Configure JAVA_HOME on RHEL 9.