DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Running an ASP.NET Core Web Application on ECS

Running an ASP.NET Core Web Application on ECS

In this post, we go over how to set up a cloud instance, and get an ASP.NET Core-based web application up and running on it using Nginx.

Leona Zhang user avatar by
Leona Zhang
·
Sep. 18, 18 · Tutorial
Like (1)
Save
Tweet
Share
6.63K Views

Join the DZone community and get the full member experience.

Join For Free

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 the 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.

Why Alibaba Cloud ECS?

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.

  1. Create new Alibaba Cloud ECS Instance.
  2. Create a new .NET Core web application using Microsoft Visual Studio.
  3. Log into ECS Instance.
  4. Install .NET Core Runtime on ECS.
  5. Deploy your source code to ECS Instance.
  6. Configure Nginx.
  7. Run the application.

You should have a valid Alibaba Cloud account. If you don't have one already, sign up for the free trial. 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.

Create a New .NET Core Web Application Using Microsoft Visual Studio

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

  1. Open Visual Studio. Go to File > New Project. Under the C# node, select Web, then select ASP.NET Core Web Application. Give your application any name (do not include spaces in the name).
  2. Click Ok, then select Web Application (Model – View – Controller). set  Authentication to No Authentication. Click Okay.
  3. Run the Application and confirm that it runs on localhost in your browser.
  4. Commit your code and push it to GitHub (or any repository service).

Log Into ECS Instance

I will be using Ubuntu on Windows to SSH into the instance. To learn how to install any Linux distro on Windows, see this article in the Microsoft docs.

  1. Go to the console, click on your ECS Instance.
  2. Under Configuration Information, copy the Internet IP Address. It should look like this: 47.89.106.74
  3. Open your terminal and type ssh root@YOUR_IP_ADDRESS (replace YOUR_IP_ADDRESS with the Instance Internet IP Address).
  4. You will see a warning, answer yes. Enter your set password. You should now see your ECS welcome message.

Install .NET Core Runtime on ECS

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

Type dotnet –version to confirm that the .NET Core runtime is installed.

Deploy Source Code to ECS Instance

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:

git clone https://github.com/vnwonah/AlibabaCloudECSDeploy

CD into the directory containing the .csproj file. In our case we use the command:

cd AlibabaCloudECSDeploy/AlibabaCloudECSDeploy

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.

Configure Nginx

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 the browser and navigate to your ECS public IP address and you will see your ASP.NET Core application now running.

Conclusion

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 a server on it.

Entity component system application ASP.NET ASP.NET Core Web application Web Service .NET Cloud computing Alibaba Cloud

Published at DZone with permission of Leona Zhang. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Real-Time Analytics for IoT
  • gRPC on the Client Side
  • Key Elements of Site Reliability Engineering (SRE)
  • Required Knowledge To Pass AWS Certified Solutions Architect — Professional Exam

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: