Provision a Virtual Machine on Azure and Install an Nginx Web Server

Video

Introduction

This tutorial is designed for individuals with a basic understanding of cloud concepts and who are interested in learning how to set up a virtual machine (VM) on Azure and deploy an Nginx web server. We will go step-by-step through the process, emphasizing best practices and troubleshooting.

Method

Prerequisites

Provision a Virtual Machine

  1. Log into Azure Portal

  2. Create a New Resource Group (this step can also be done in the next step - in the wizard for creating a VM)

    • Within the portal, find and select “Resource groups”.
    • Fill out the basic settings:
      • Select the Subscription
      • Specify a resource group name
      • Select the Region (preferably one closest to you for reduced latency).
    • Click on “Review + create” and then “Create” to create the new resource group.
  3. Create the VM

    • Go to “Virtual machines” and then click on “Create” -> “Azure virtual machine”.
    • Fill out the basic settings:
      • Subscription and resource group (create a new one if you skipped step 2)
      • Virtual machine name.
      • Region (preferably one closest to you for reduced latency).
      • Availability options as per your requirement.
      • Image: Ubuntu Server 22.04 LTS - x64 Gen2.
      • Size: “Standard_B1ls” is the cheapest and often good for testing.
    • Under the “Administrator account” section, choose “SSH public key” if you’re familiar with SSH, or “Password” for a simpler setup.
    • In the “Inbound port rules” section:
      • Select inbound ports: allow HTTP (port 80) and SSH (port 22).
    • Navigate to the “Advanced” tab, find the “Custom Data” section, and paste your cloud-init script (provided below).
      #!/bin/bash
      apt-get update -y
      apt-get install nginx -y
      systemctl start nginx
      systemctl enable nginx
      
    • Once all details are filled in, review the configuration by clicking “Review + create” and then click “Create”.
    • Download the SSH private key from the popup dialog box (if you chose SSH above)
  • Choosing a region close to you or your users minimizes latency.
  • The “Standard_B1s size is cost-effective for small projects and testing environments, but you should choose based on your specific needs.
  • Ubuntu 22.04 LTS offers long-term support and stability.

Accessing the VM

azureuser is the default user for azure VMs

Verify Nginx Installation

Additional Configuration (Optional)

Troubleshooting

Final Thoughts

Limitations:

Don’t Forget

Azure services incur costs based on resource consumption, including VM instances, outbound data transfers, and more. It’s important to monitor your usage and manage resources effectively to avoid unexpected charges.

Remember to delete resources you no longer need to prevent ongoing charges.

Happy cloud computing! 🚀