Deploying a Linux Virtual Machine with Nginx on Microsoft Azure
Tags: azure, cloud
Published: 2024-06-10 23:51:36

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](https://azure.microsoft.com/en-us/pricing/offers/ms-azr-0044p).

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6tf464nvi3xfl68evv6g.jpg)

### Create a New Virtual Machine

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o02v6sc4fvuuuqeyb025.jpg)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oex53w8mqeqjeg0yr9nv.jpg)

#### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hdhr4ic5ai77qobsnn40.jpg)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnzpzin5gctmqexmj8iq.jpg)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de1b4fgt2utyzi6qqdsp.jpg)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1v64pd9gmu20pvet7otq.jpg)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0uh08k4etalmgkdg25y.jpg)

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2q5qkbyje3d8t9zizafl.jpg)

## 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.