Popular blog tags

How to Deploying Real World ASP.NET Core Blazor WebAssembly 6.x(Hosted deployment ) on Ubuntu 20.04 step by step



In this tutorial you’ll set up and deploy a production-ready ASP.NET Core Blazor WebAssembly(Hosted deployment) with a MongoDb Server on Ubuntu 20.04 using Nginx.

A standalone deployment serves the Blazor WebAssembly app as a set of static files that are requested directly by clients. Any static file server is able to serve the Blazor app.

1.Hosted deployment with ASP.NET Core


2.Standalone deployment



How it works

Remember the relationships.

OS/ ubuntu server 18.04-x64 Solution Folder

OS---------- ubuntu server 18.04-x64 
 ├── .NET SDK & .NET  Runtime
 │   ├── .NET SDK                     <- ---------- SDK
 │   ├── ASP.NET Core Runtime    <--- The ASP.NET Core Runtime enables you to run existing web/server applications.
 │   ├── Desktop Runtime            <--- The Desktop Runtime enables you to run existing Windows desktop applications.
 │   └── .NET Runtime                   <---  The .NET Runtime enables you to run existing  console app.
 ├── ASP.NET Core  web applications   <---- Listens on http://locahost:5000
 │   ├── nongodb server
 │   └── redis server
 └── Nginx web server   <--- Listens on Port 443 / 80 and forwards HTTP/S calls to http://locahost:5000.

One Ubuntu 18.04 server - Your server

ASP.NET Core Web Application - Runs your app / website on  Ubuntu 18.04 server
nginx - Listens on Port 443 / 80 and forwards HTTP/S calls to your website.

A secured Nginx web server
Mongodb Redis - Keeps your app data
Supervisor - Keeps your app running


detail steps


Register Microsoft key and feed
Install the .NET Core  Runtime
Install the .NET SDK

Create a new ASP.NET Core web application
Publish and copy over the app
Install Monodb
Install nginx as reverse proxy
Configure SSL
Configure nginx
Monitoring the app


Prepare an  Run Evironmentn for ASP.NET Core Application on Ubuntu

Install the .NET Core 6.x Runtime <--an  Run Evironmentn for ASP.NET Core Application on Ubuntu
Install the .NET Core 6.x SDK        <--an  Run Evironmentn for ASP.NET Core Application on Ubuntu

Prepare an ASP.NET Core Website

insall web <--Running an ASP.NET Core Website on Ubuntu

install mongodb

install redis


insall nginx

Configure NGINX<--Configure NGINX as a Reverse Proxy to ASP.NET Core

install https<--Configure the reverse proxy for secure (HTTPS) client connections


buy domain


Part one:Prepare an  Run Evironmentn for ASP.NET Core Application on Ubuntu

step 1.Setting up a Linux host


Linux Distribution

   ubuntu 18.04-x64

   root permissions

2.One Ubuntu 18.04 server

There are many service providing offering a cheap Linux based VPS (virtual private server). vultr.com offers  a single core, 1GB RAM instance for  about 5 USD/month. The instance we select is an Ubuntu Server 20.04 *64 LTS (HVM) with 8GB of storage (SSD).

3.NET  6.0 - Supported OS versions

.NET Core 6.0 is supported on the following Linux distributions/versions:

Ubuntu OS Version >=16.04* 64,
Architectures:x64, ARM32, ARM64

For information on  Linux distributions supported by ASP.NET Core, see Prerequisites for .NET Core on Linux.



step 2. connect to this instance through SSH

1.On a Windows machine, you can use mRemoteNG to connect to a Linux machine. 

2.PuTTY: a free SSH and Telnet client


3.Xshell6 https://www.netsarang.com/en/all-downloads/

4.Termius SSH:https://www.termius.com/windows


step 3.Prepare an  Run Evironmentn for ASP.NET Core Application on Ubuntu

Prepare ASP.NET Projects

Initial Server Setup with Ubuntu 18.04 

How To Install Nginx on Ubuntu 18.04


Install winscp on windows


文件传输协议 = SFTP-3
加密协议 = SSH-2
SSH实现 = OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
加密算法 = aes
压缩 = 否


other tools:

SecureCRT+SecureFX  https://www.portablesoft.org/securecrt-securefx-legacy-versions/


# lsb_release -a

LSB Version:	core-9.20170808ubuntu1-noarch:security-9.20170808ubuntu1-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.3 LTS
Release:	18.04
Codename:	bionic



Install .NET Core SDK on Linux Ubuntu 20.04 - x64


you can read the doc https://dotnet.microsoft.com/download/linux-package-manager/ubuntu18-04/sdk-current and  run the  commands.

This tutorial installs .Net core 5.x on  ubuntu 18.04-x64 .

how to Install .NET5.x on Ubuntu 18.04*64 step by step




If the command runs, printing out information about dotnet, you're good to go.

step 4:Website Creation

The dotnet command creates a new website server application of type website for you. The -o parameter creates a directory named test where your app is stored, and populates it with the required files. The cd myApp command puts you into the newly created app directory.

step5:Run the app

Kestrel is the web server that is included by default in ASP.NET Core new project templates. It is a cross-platform web server for ASP.NET Core based on libuv, a cross-platform asynchronous I/O library. If your application accepts requests only from an internal network, you can use Kestrel by itself.



dotnet run --urls http://localhost:5005



dotnet run --urls
warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to http://localhost:5005 on the IPv6 loopback interface: 'Cannot assign requested address'.
Hosting environment: Development
Content root path: /root/myapp/test
Now listening on: http://localhost:5005
Application started. Press Ctrl+C to shut down.


step 5:Test the Application Directly on Kestrel Server

navigate to http://<serveraddress>:<port> to verify the app works on Linux locally.

visit http://localhost:5000/。,open another terminal

wget http://localhost:5000/




Step 6: publish  on vultr

cd /var/www/msly/Toolmslycn_BlazorWebAssembly/src/Server

dotnet publish -c release


Toolmslycn_BlazorWebAssembly.Server -> /var/www/msly/Toolmslycn_BlazorWebAssembly/src/Server/bin/release/net6.0/publish/


 Step 7:Test the Application Directly (  publish )

cd  /var/www/msly/Toolmslycn_BlazorWebAssembly/src/Server/bin/release/net6.0/publish/
dotnet Toolmslycn_BlazorWebAssembly.Server.dll --urls http://localhost:4899



We use the following command to list the available releases of .NET Core on Linux host.

apt-cache search dotnet


Step 8:Configure ASP.NET Core as a Background Service

 We will use systemd and create a service file to start and monitor the underlying web app. systemd is an init system that provides many powerful features for starting, stopping and managing processes.

We can create a configuration file using the following command

sudo vi /etc/systemd/system/kestrel-wwwstocksocom.service

The content of the .sevice file is as follows.

Description=Toolmslycn BlazorWebAssembly App Server running on Ubuntu

ExecStart=/usr/bin/dotnet  /var/www/msly/Toolmslycn_BlazorWebAssembly/src/Server/bin/release/net6.0/publish/Toolmslycn_BlazorWebAssembly.Server.dll --urls http://localhost:4899
# Restart service after 10 seconds if the dotnet service crashes:


If you completed the configuration and save the .service file, you need to enable it.

sudo systemctl enable kestrel-wwwstocksocom.service

then start it.

sudo systemctl start kestrel-wwwstocksocom.service
sudo systemctl restart kestrel-wwwstocksocom.service


sudo systemctl status kestrel-wwwstocksocom.service


sudo journalctl -fu kestrel-wwwstocksocom.service


sudo systemctl daemon-reload 

在你的Linux 里确认 8045 处于 Listen 状态用命令: netstat -tlanp | grep 8045

端口范围  80/80






1.dotnet publish

2.copy in\Debug\netcoreapp2.1\publish\*.* to linux  var/www/

3.cd var/www/publish

4.dotnet project.dll