Another option would be the following:
Step 1: Install .NET Runtime on the Server
Connect to Your Server:
Use SSH to connect to your Linux server.
Install Required Dependencies:
Ensure your server has the required dependencies for .NET. You can use the following commands for Debian/Ubuntu:
sudo apt-get update
sudo apt-get install -y wget apt-transport-https
Add Microsoft Package Repository:
Add the Microsoft package repository to your server:
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Install .NET Runtime:
Install the .NET runtime:
sudo apt-get update
sudo apt-get install -y dotnet-runtime-6.0
Adjust the version number (6.0 in this example) according to your application's requirements.
Step 2: Deploy Your .NET Application
Publish Your Application:
Publish your .NET application for Linux. Use the following command in your development environment:
dotnet publish -c Release -r linux-x64 --self-contained
This command generates a self-contained deployment in the bin/Release/net6.0/linux-x64/publish directory.
Upload Your Application:
Upload the published application files to your Plesk server using SFTP or a file manager.
Place Application Files:
Place the application files in the appropriate directory on your server, usually under /var/www/vhosts/yourdomain.com/httpdocs.
Step 3: Configure the Application
Create a Service File:
Create a systemd service file to manage your application.
Create a new file /etc/systemd/system/yourapp.service with the following content:
[Unit]
Description=Your .NET Application
After=network.target
[Service]
WorkingDirectory=/var/www/vhosts/yourdomain.com/httpdocs
ExecStart=/var/www/vhosts/yourdomain.com/httpdocs/yourapp
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=yourapp
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Adjust the WorkingDirectory and ExecStart paths according to your application's location.
Reload Systemd and Start the Service:
Reload systemd to recognize the new service and start it:
sudo systemctl daemon-reload
sudo systemctl start yourapp.service
sudo systemctl enable yourapp.service
Step 4: Configure Plesk
Proxy Pass Configuration:
In Plesk, set up a proxy pass to forward requests to your .NET application. Go to your domain's settings, and add the following in the Apache & nginx Settings:
For Apache:
ProxyPass /
http://127.0.0.1:5000/
ProxyPassReverse /
http://127.0.0.1:5000/
For nginx:
location / {
proxy_pass
http://127.0.0.1:5000
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;
}
Adjust the port number (5000 in this example) if your application listens on a different port.
Step 5: Test Your Application
Access Your Application:
Open your web browser and navigate to your domain to verify that the application is running correctly.