Ubuntu Servers and ASP.net Core Project Deployment using Nginx

Hidayat Arghandabi
Dec 25, 2018 · 3 min read

.NET is a free, cross-platform, open source developer platform for building many different types of applications.

Linux servers are cheaper to deploy dotnet core projects.

In this article I will be explaining, how to deploy a dotnet core project in a Ubuntu 16.04 Linux GUI or NON-GUI servers.

Step 1: Log in to your Linux server, Install the Prerequisites

Register Microsoft key and feed

wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.debsudo dpkg -i packages-microsoft-prod.deb

Install the .NET SDK

sudo apt-get install apt-transport-httpssudo apt-get updatesudo apt-get install dotnet-sdk-2.2

To confirm your installation and to check the version of dotnet cli installed on the machine type the following command. You should get an output

dotnet —-version

Output: The version installed in my server is 2.2.101

Step 2: Install Nginx

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability.

Install Nginx

sudo apt-get install nginx

Start Nginx Server

sudo service nginx start

Server Status: Check the server status if running

sudo service nginx status

You can see that the server is active

Step 3: Configure Nginx

To configure Nginx as a reverse proxy to forward requests to our ASP.NET Core app. Modify (nano) /etc/nginx/sites-available/default.

nano /etc/nginx/sites-available/default

Or Open it in a text editor, and replace the contents with the following: This Nginx configuration file forwards incoming public traffic from port 80 to port 5000.

server {listen 80;location / {proxy_pass http://localhost:5000;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection keep-alive;proxy_set_header Host $http_host;proxy_cache_bypass $http_upgrade;}}

NOTICE: The localhost port can change upon your project

After the modification we need to verify the syntax of the configuration file

sudo nginx -t

If the configuration file test is successful, force Nginx to pick up the changes by running

sudo nginx -s reload

Or start it with:

sudo service nginx start

Now your go to your nginx server adress and you see that you application has started working.

Step 4: Register Project Nginx in a service file

Go to the the following directory tree and deploy the appliaction.


Deploy the application in your dirctory (mkdir build)


After the application is clone to your ubuntu. In the application directory , check if it runs

/var/www/ForExample/ForExample# dotnet run

Deploy in a build directory

/var/www/ForExample/ForExample# dotnet publish — output “ /var/www/build” — configuration release

Go to the build directory and run the application

/var/www/build# dotnet ForExample.dll

Create the service file

sudo nano /etc/systemd/system/kestrel-ForExample-test.service

and paste

[Unit]Description=Example .NET Web API App running on Ubuntu[Service]WorkingDirectory=/var/www/ForExample/ForExampleExecStart=/usr/bin/dotnet /var/www/build/ForExample.dllRestart=always# Restart service after 10 seconds if the dotnet service crashes:RestartSec=10KillSignal=SIGINTSyslogIdentifier=dotnet-exampleUser=www-dataEnvironment=ASPNETCORE_ENVIRONMENT=ProductionEnvironment=DOTNET_PRINT_TELEMETRY_MESSAGE=false[Install]WantedBy=multi-user.t

Register the service

sudo systemctl enable kestrel-ForExample-test.service

Start the service and verify that it’s running.

sudo systemctl start kestrel-mebgispanel-test.servicesudo systemctl status kestrel-mebgispanel-test.service

Check the server logs

sudo journalctl -fu kestrel-helloapp.service

Your application is successfully running in Nginx server.

Join our community Slack and read our weekly Faun topics ⬇

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇


The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts

Hidayat Arghandabi

Written by

Full-Stack Software Developer | Open-Source Contributor https://www.linkedin.com/in/hidayatarg/



The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade