Create HTTP with NGINX on Linux in Azure Virtual Machine

HTTP with NGINX on Linux in Azure Virtual Machine

Today in this article, we shall see how to Create HTTP with NGINX on Linux in Azure Virtual Machine.

We shall create a Linux Virtual machine with an NGINX webserver and deploy our first application using basic commands and later we will also see how to create an ASP.NET MVC Core application.

Below are the steps we will follow,

Getting started

Sign in to Azure

Sign in to the Azure portal if you haven’t already.

Create a VM on Ubuntu using SSH and HTTP

  • On the Virtual machines page, select Create. The Create a virtual machine page opens.

  • In the Basics tab, under Project details, please use the correct subscription and then choose to Create a new resource group. Type the name of your choice for the name.*

Create VM on Ubuntu using SSH and HTTP

  • Under Instance details,-> for the Virtual machine name -type VM name <vm-name>,

Example

  • choose East US as region or region of your choice and
  • choose Ubuntu 20.04 LTS for your Image.

Linux Virtual machine with NGINX

  • Under Administrator account, select SSH public key as Authentication Type

  • In Username* specify the user name of your choice

HTTP with NGINX on Linux in Azure Virtual Machine

  • For Key pair name
  • For SSH public key source, you can leave the default of Generate new key pair.

  • For Inbound port rules > Public inbound ports,
    • choose to Allow selected ports and then
    • select SSH (22) and HTTP (80) from the drop-down.

Screenshot of the inbound port rules section where you select what ports inbound connections are allowed on

  • Select the Review + create 

On the Create a virtual machine page, you get an option to create the Virtual machine.

Download the private key

blank

From the Generate new key pair window,->select Download private key and create the resource.

A private key file will be downloaded to your machine

Example- vmfirst_key.pem

Installing NGINX on Azure Virtual Machine

In previous steps, we created VM successfully. Let’s first connect to VM.

Connect to Virtual Machine

Please go to VM ->Overview-> Connect

Here you will get the Connect option using either SSH or RDP or Bastion

blank

Copy the above command highlighted.

The above commands grab your IP along with the command sample for establishing the connection with the VM.

We will use the above commands in the next step.

Commands copied from above are as below

chmod 400 azureuser.pem

ssh -i azureuser@<Your Public IP for VM>

Using Cloudshell to run SSH commands

Open the Cloudshell CLI command line lets upload the downloaded private key

blank

Please run the below set of commands to connect.

ls

chmod 400 azureuser.pem

ssh -i vmfirst_key.pem azureuser@20.127.10.153

blank

Install NGINX

Please run the below set of commands,

sudo apt-get -y update
sudo apt-get -y install nginx
Install NGNIX Azure

View Webserver with web application

Once you hit the IP – you shall see a Welcome message from NGINX,

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

Let’s add a custom hello message to the Webserver using index.html

azureuser@vmfirst:~$ sudo su

root@vmfirst:/home/azureuser# echo "Hello TheCodeBuzz"> /var/www/html/index.html
NGINX

Note: Please run the command Sudo su to make you a superuser.

Without Sudo su you will get a Permission denied error.

Setup HTTPS for secured access

As we can see in the screenshot access to our web application is not secure.

To make it secure, we will need to install an SSL certificate and we will enable PORT 443 for Secured access.

I shall cover this in my next article. Until then kindly stay tuned!

Other References:

Do you have any comments or ideas or any better suggestions to share?

Please sound off your comments below.

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *