Welcome, Guest • Great software is not cheap to make.

.NET 8 Core Web Application Deployment Guide

Views: 11 | Like0 | Comments: 0

This guide will walk you through installing the .NET 8 runtime, setting up Nginx, configuring your application as a systemd service, and setting up SSL on Ubuntu 24.04 LTS.

Step 1: Install the .NET 8 Runtime

  1. Add Microsoft’s package repository:

    wget https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    sudo apt update
  2. Install the .NET 8 runtime (ASP.NET Core runtime):

    sudo apt install -y aspnetcore-runtime-8.0
  3. Verify the installation:

    dotnet --info

Step 2: Publish and Deploy Your .NET Core Application

  1. Publish your .NET application:

    dotnet publish --configuration Release --output /path/to/publish/folder
  2. Transfer the published files to your server:

    Use SCP or FileZilla to transfer your published files to the server. Place them in /var/www/appweb.

    scp -r /path/to/publish/folder username@your-server:/var/www/appweb

Step 3: Configure Nginx

  1. Install Nginx:

    sudo apt install -y nginx
  2. Create an Nginx configuration file for your app:

    sudo nano /etc/nginx/sites-available/appweb
  3. Add the following Nginx configuration:

    server {
        listen 80 default_server;
        server_name test.coolnailz.com;
    
        location / {
            proxy_pass http://localhost:5000;  # Ensure your app is running on port 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;
            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;
        }
    }
  4. Enable the Nginx site:

    sudo ln -s /etc/nginx/sites-available/appweb /etc/nginx/sites-enabled/
  5. Disable the default Nginx site (optional):

    sudo rm /etc/nginx/sites-enabled/default
  6. Test the Nginx configuration:

    sudo nginx -t
  7. Reload Nginx:

    sudo systemctl reload nginx

Step 4: Set Up a systemd Service for the .NET Application

  1. Create a systemd service file:

    sudo nano /etc/systemd/system/appweb.service
  2. Add the following content:

    [Unit]
    Description=.NET 8 AppWeb Application
    
    [Service]
    WorkingDirectory=/var/www/appweb
    ExecStart=/usr/bin/dotnet /var/www/appweb/AppWeb.dll
    Restart=always
    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=dotnet-appweb
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Production
    
    [Install]
    WantedBy=multi-user.target
  3. Enable and start the systemd service:

    sudo systemctl enable appweb.service
    sudo systemctl start appweb.service
  4. Check the status of the service:

    sudo systemctl status appweb.service

Step 5: Test the Application

  1. Access via IP: Open a browser and go to http://your_server_ip

  2. Access via Domain: Open a browser and go to http://test.coolnailz.com

Step 6: Configure HTTPS (Optional but Recommended)

  1. Install Certbot:

    sudo apt install -y certbot python3-certbot-nginx
  2. Obtain an SSL certificate for your domain:

    sudo certbot --nginx -d test.coolnailz.com
  3. Verify SSL auto-renewal:

    sudo certbot renew --dry-run

Step 7: Verify Everything is Working

  1. Check Nginx logs:

    sudo tail -f /var/log/nginx/error.log
  2. Check .NET application logs (systemd):

    sudo journalctl -fu appweb.service

Conclusion

This guide provides all the steps to deploy a .NET 8 Core web application on Ubuntu 24.04, configure Nginx, create a systemd service for automatic startup, and optionally enable HTTPS. Follow these steps to ensure your application is deployed securely and is always running.

You describe it, I build it

Great software is not cheap to make.
My Projects
AB953: Racial and Identity Profiling Act Stop Data
Online Services
Merge PDF Files
PrivacyAboutContact