Sitemap

Hosting ASP.NET Core 2.0 Web Api on Azure Ubuntu Server with Nginx and Mutual SSL Authentication (PART 2)

Mert Ilis
3 min readNov 23, 2017

PART 2: Configuring Ubuntu, .Net Core and Nginx

In this post series, I will step by step show you how to host a ASP.NET Core 2.0 Web Api which is using mutual SSL authentication on a Azure Ubuntu Server using Nginx as the reverse proxy server and Kestrel as the default application server.

In this part we will see how to setup .Net Core SDK 2.0 and Nginx on Ubuntu Linux server.

For information about how to deploy an Ubuntu Server in Azure check part-1 of this series.

For information about how to configure Azure Network Security Group and Publishing Asp.Net Core Web Api check part-3 of this series.

For information about how to setup a service to manage kestrel process, creating self-signed SSL certificate and configuring Nginx as a reverse proxy server check part-4 of this series.

For information about how to setup mutual SSL for client authentication and passing client certificate data to Asp.Net Core Web Api using HTTP headers check part-5 of this series.

Install .Net Core SDK on Ubuntu Linux

First let’s start with updating our server:

sudo apt-get -y update

Register the trusted Microsoft signature key:

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

Register the Microsoft Product feed for Ubuntu 17.04:

sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-zesty-prod zesty main" > /etc/apt/sources.list.d/dotnetdev.list'

Install .Net SDK:

sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.2

Disabling Telemetry:

export DOTNET_CLI_TELEMETRY_OPTOUT=1

To check whether the installation is succeeded:

dotnet --version

This should display “2.0.2”.

Install Nginx

First, install nginx key (to authenticate the nginx repository signature and to eliminate warnings about missing PGP key during installation of the nginx package, it is necessary to add the key used to sign the nginx packages and repository to the apt program keyring).

sudo wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key

Open the /etc/apt/sources.list file with Nano editor:

sudo nano /etc/apt/sources.list

Append the following to the end of file:

deb http://nginx.org/packages/mainline/ubuntu/ zesty nginxdeb-src http://nginx.org/packages/mainline/ubuntu/ zesty nginx

NOTE: zesty is the codename for Ubuntu version 17.04. In your case if you are running a different version, write the appropriate codename instead of “zesty”!

If you get a GPG error: http://nginx.org/packages/ubuntu xenial Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY $key is encountered during the NGINX repository update, execute the following:

## Replace $key with the corresponding $key from your GPG error.sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key

You can get the latest stable version of NGINX from the NGINX PPA on Launchpad: (PPA is maintained by volunteers and is not distributed by nginx.org. It has some additional compiled-in modules and may be more fitting for your environment). You have options like “stable”, “development”. (“development” contains the latest ‘Mainline’ Release version of the nginx web server software. You can also consider it as a stable version!)

sudo add-apt-repository ppa:nginx/development

If you prefer to install from “stable” release instead of the above one execute this command:

sudo add-apt-repository ppa:nginx/stable

Now, we are ready to install Nginx:

sudo apt-get update
sudo apt-get install nginx-extras

Since Nginx was installed for the first time, explicitly start it by running:

sudo systemctl start nginx.service && sudo systemctl enable nginx.service

To verify nginx installation:

sudo nginx -v

This should display “nginx version: nginx/1.13.3”

Our series will continue with configuring Azure for inbound port rules and publishing our .Net Core web api.

Hope it helps!

Originally published at https://www.weboideas.com on November 23, 2017.

--

--

Mert Ilis
Mert Ilis

Written by Mert Ilis

I’m a software development enthusiast who likes trying different web technologies and adding value to his team.

No responses yet