ASP.NET Core is a Microsoft Web Framework for developing Web Applications that can run in any environment, including Windows and Linux servers. According to Microsoft Docs:
"ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications."
This tutorial provides detailed step by step instructions for a first time Alibaba Cloud user to create a Linux Elastic Compute Service (ECS) instance and host an ASP.NET Core Application on it.
Alibaba Cloud Elastic Compute Service (ECS) provides fast memory and the latest Intel CPUs to help you to power your cloud applications and achieve faster results with low latency. All ECS instances come with Anti-DDoS protection to safeguard your data and applications from DDoS and Trojan attacks.
For this tutorial, our setup uses the Nginx Web Server to forward requests to a running ASP.NET core application. We will follow the under-listed steps to successfully create and deploy an ASP.NET Core Web Application to Alibaba Cloud ECS.
You should have a valid Alibaba Cloud account. If you don't have one already, sign up to the Free Trial to enjoy up to $300 worth in Alibaba Cloud products. To create a new Alibaba Cloud ECS instance, you can follow the steps in this tutorial. You can also refer to this tutorial to set up your first Ubuntu server on Alibaba Cloud.
We assume that you already have Visual Studio installed on your local machine. If you want to skip this step you can use a repo I already created at https://github.com/vnwonah/AlibabaCloudECSDeploy
I will be using Ubuntu on Windows to SSH into the Instance. To learn how to install any Linux distro on Windows see article here.
ssh root@YOUR_IP_ADDRESS. (Replace YOUR_IP_ADDRESS with the Instance Internet IP Address.
To run our .NET Web Application on Alibaba Cloud we need to install the .NET Core Runtime. Use the following commands:
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-2.1
dotnet –version to confirm that the .NET Core Runtime is installed.
Now we will pull our source code into the ECS Instance. For this tutorial we will simply pull into our user folder.
Install git on the ECS instance. First run
apt-get update, then run the command
apt install git. Confirm that git installed successfully by typing
git –version and see the output.
Install libunwind08 with the command:
sudo apt-get install libunwind8
Clone your repository using:
CD into the directory containing the .csproj file. In our case we use the command:
Then type the command:
dotnet publish -c Release -o ./published -r linux-x64
This restores all dependencies for our project and builds a .dll file. At this point we are ready to configure Nginx and use it to forward requests to our application.
In this section, we will install and configure Nginx to proxy requests to our .NET Core Web Application.
Install Nginx with the command
sudo apt-get install nginx. This command installs the Nginx Web Server. At this point if you open your ECS Public IP Address in a browser, you should see the Nginx Welcome Page.
We need to configure Nginx to forward requests to the .NET Core Application. To do this, run the command
sudo pico /etc/nginx/sites-enabled/default, clear everything in the file and type in
[Unit] Description=Alibaba Cloud Net Core App [Service] WorkingDirectory=/root/netcoreapp ExecStart=/usr/bin/dotnet /root/AlibabaCloudECSDeploy/ALibabaCloudECSDeploy/AppName.dll Restart=always RestartSec=10 # Restart service after 10 seconds if dotnet service crashes SyslogIdentifier=dotnet-core-app User=root Environment=ASPNETCORE_ENVIRONMENT=Production [Install] WantedBy=multi-user.target
Now enable the service using the command
sudo systemctl enable dotnet-core-app.service and start it using
sudo systemctl start dotnet-core-app.service.
At this point you should open a browser and navigate to your ECS Public IP Address and you will see your ASP.NET Core Application now running.
In this article we went from creating a new Alibaba Cloud Elastic Compute Service (ECS) Instance to hosting a .NET Core Web Application using Nginx as Server on it.
Alibaba Clouder - November 27, 2018
Alibaba Clouder - March 6, 2019
Alibaba Clouder - November 29, 2017
Alibaba Clouder - June 7, 2018
Alibaba Clouder - November 1, 2018
Alibaba Cloud Product Launch - December 11, 2018
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
A high-performance container manage service that provides containerized application lifecycle managementLearn More
A virtual private cloud service that provides an isolated cloud network to operate resources in a secure environment.Learn More
More Posts by Alibaba Clouder