DEV Community

Cover image for Deploying a Linux Virtual Machine with Nginx on Microsoft Azure
Jimi
Jimi

Posted on

Deploying a Linux Virtual Machine with Nginx on Microsoft Azure

This blog post guides you through the process of creating a Linux virtual machine (VM) on Microsoft Azure and installing the popular web server Nginx.

Prerequisites

  • An active Microsoft Azure subscription. If you don't have one, you can sign up for a free trial.

Step-by-Step Guide

Access the Azure Portal and Locate Virtual Machines

  • Log in to the Azure portal and navigate to the "Virtual machines" service. You can use the search bar or browse through the services listed under "Services."

Image description

Create a New Virtual Machine

  • Click the "Create" button and select "Virtual machine" to initiate the VM creation process.

Image description

Configure Virtual Machine Settings

Basic Settings

  • Resource Group: Choose an existing resource group or create a new one by entering a desired name. This group will organize your Azure resources.
  • Virtual Machine name: Provide a unique and descriptive name for your VM.

Image description

Instance Details

  • Image: Select the "Ubuntu Server 20.04 LTS" image for a stable and widely supported Linux environment.
  • VM size: Choose a recommended size based on your anticipated workload. You can adjust this later based on your needs.

Administrator Account

  • Authentication type: Select "Password" for a basic login setup.
  • Username: Create a secure username for administrative access to the VM.
  • Password: Enter a strong password and confirm it.

Configure Inbound Ports

  • Under "Networking," locate the "Inbound ports" section. Ensure the checkbox for "HTTP (80)" is selected. This allows external communication with your web server.

Image description

Review and Create

  • Carefully review all your configuration choices. Once satisfied, click "Review + create" followed by "Create" to initiate the VM deployment process. The portal will display the deployment progress.

Access the Virtual Machine

  • Once deployment is complete, navigate to your VM resource and click "Go to resource."

Image description

Locate Public IP Address

  • Within the VM resource overview, find the public IP address. You'll need this to connect to your VM remotely.

Image description

Connect using SSH

  • Open a command-line interface (CLI) tool like Windows PowerShell or Ubuntu terminal. Use the following SSH command, replacing the bracketed placeholders with your actual credentials:

ssh [username]@[public_ip_address]

Enter in the password you created for the user.

Image description

When prompted, confirm that you want to connect by typing "yes" and pressing Enter.

Update and Install Nginx

  • Switch to the root user with sudo su.
  • Update your package lists with apt update and install Nginx using apt install nginx.

Image description

Test Your Web Server

  • Open a web browser and enter the public IP address you obtained earlier. If Nginx is running correctly, you should see a default welcome page.

Congratulations! You have successfully created a Linux virtual machine on Microsoft Azure and installed the Nginx web server. This is a foundational step for hosting web applications or deploying other web services.

Image description

Additional Notes

  • For enhanced security, consider using SSH key-based authentication instead of passwords.
  • Explore further configuration options for Nginx to customize your web server behavior.
  • Remember to configure security groups and firewalls within Azure to manage inbound and outbound traffic for your VM.

By following these steps and considering the additional notes, you can leverage the power of Azure and Nginx to build and deploy your web applications.

Top comments (0)