Creating Microsoft Azure Virtual Machines for NGINX Open Source and F5 NGINX Plus

These instructions explain how to create virtual machines (VMs) in the Microsoft Azure environment that are suitable for running NGINX Open Source and NGINX Plus.

The names and other settings used in this guide are appropriate for the high‑availability deployment described in Active-Active HA for NGINX Plus on Microsoft Azure Using the Azure Standard Load Balancer, but the VMs can be used for any purpose.

For NGINX Plus, a faster alternative is to purchase a prebuilt VM in the Microsoft Azure Marketplace (several current operating systems are available). For instructions, see Installing NGINX Plus on Microsoft Azure.

Prerequisites

These instructions assume you have:

In addition, to install NGINX software by following the linked instructions, you need:

  • An NGINX Plus subscription, either paid or a 30‑day free trial, if you plan to install that product.
  • root privilege on the hosts where NGINX Open Source and NGINX Plus are to be installed. If appropriate for your environment, prefix commands with the sudo command.

Creating a Microsoft Azure Virtual Machine

  1. Access the Microsoft Azure portal (https://portal.azure.com/) and sign in.

  2. Click the Virtual machines icon. (If that icon doesn’t appear at the top of your window, click the stacked‑lines icon in the upper left corner of the title bar and click Virtual machines in the navigation column that opens at left.)

    screenshot of top navigation bar at Microsoft Azure portal
  3. On the Virtual machines page that opens, click + Add in the upper left corner.

    screenshot of Azure 'Virtual machines' page

  4. In the Create a virtual machine window that opens, enter the requested information on the Basics tab. In this guide, we’re using the following values:

    • Subscription – NGINX-Plus-HA-subscription

    • Resource group – NGINX-Plus-HA

    • Virtual machine name – ngx-plus-1

      The value ngx-plus-1 is one of the six used for VMs in Active-Active HA for NGINX Plus on Microsoft Azure Using the Azure Standard Load Balancer. See Step 7 below for the other instance names.

    • Region – (US) West US 2

    • Availability options – No infrastructure redundancy required

      This option is sufficient for a demo like the one in this guide. For production deployments, you might want to select a more robust option; we recommend deploying a copy of each VM in a different Availability Zone. For more information, see the Azure documentation.

    • Image – Ubuntu Server 18.04 LTS

    • Azure Spot instance – No

    • Size – B1s (click Select size to access the Select a VM size window, click the B1s row, and click the  Select  button to return to the Basics tab)

    • Authentication type – SSH public key

    • Username – nginx_azure

    • SSH public key source – Generate new key pair (the other choices on the drop‑down menu are to use an existing key stored in Azure or an existing public key)

    • Key pair name – nginx_key

    • Public inbound ports – Allow selected ports

    • Select inbound ports – Select from the drop-down menu: SSH (22) and HTTP (80), plus HTTPS (443) if you plan to configure NGINX and NGINX Plus for SSL/TLS

    screenshot of 'Basics' tab on Azure 'Create a virtual machine' page

  5. If you are creating VMs to use in Active-Active HA for NGINX Plus on Microsoft Azure Using the Azure Standard Load Balancer, the two NGINX Plus VMs in that deployment must have public IP addresses with SKU type Standard instead of the default Basic.

    For simplicity, we recommend allocating Standard public IP addresses for all six VMs used in the deployment. At the time of initial publication of this guide, the hourly cost for six such VMs was only $0.008 more than for six VMs with Basic addresses; for current pricing, see the Microsoft documentation.

    To allocate a Standard public IP address, open the Networking tab on the Create a virtual machine window. Click Create new below the Public IP field. In the Create public IP address column that opens at right, click the Standard radio button under SKU. You can change the value in the Name field; here we are accepting the default created by Azure, ngx-plus-1-ip. Click the  OK  button.

    screenshot of 'Networking' tab on Azure 'Create a virtual machine' page

  6. At this point, you have the option of selecting nondefault values on the Disks, Networking, Management, Advanced, and Tags tabs. For a demo like the one in this guide, for example, selecting Standard HDD for OS disk type on the Disks tab saves money compared to the default, Premium SSD. You might also want to create or apply tags to this VM, on the Tags tab.

    When you have completed your changes on all tabs, click the  Review + create  button at the bottom of the Create a virtual machine page.

    If all of your settings are valid, a summary of them appears under the Validation passed banner, as in the following screenshot.

    To change any settings, open the appropriate tab. If the settings are correct, click the  Create  button.

    If you chose in Step 4 to generate a new key pair, a Generate new key pair window pops up. Click the  Download key and create private resource  button.

    screenshot of validation message on Azure 'Create a virtual machine' page

    It takes a few minutes for a VM to deploy. When it’s ready, a summary of associated resources appears, as in the following screenshot.

    screenshot of Azure 'CreateVM-Canonical' page

  7. If you are following these instructions to create the six VMs used in Active-Active HA for NGINX Plus on Microsoft Azure Using the Azure Standard Load Balancer, their names are as follows:

    • ngx-plus-1
    • ngx-plus-2
    • ngx-oss-app1-1
    • ngx-oss-app1-2
    • ngx-oss-app2-1
    • ngx-oss-app2-2

    For ngx-plus-2, it is probably simplest to repeat Steps 2 through 6 above (or purchase a second prebuilt VM in the Microsoft Azure Marketplace).

    For the NGINX Open Source VMs, you can create them individually using Steps 2 through 6. Alternatively, create them based on an Azure image. To do so, follow Steps 2 through 6 above to create a source VM (naming it nginx-oss), install the NGINX Open Source software on it, and then follow the instructions in Optional: Creating an NGINX Open Source Image.

Connecting to a Virtual Machine

To install and configure NGINX Open Source or NGINX Plus on a VM, you need to open a terminal window and connect to the VM over SSH.

  1. Navigate to the Virtual machines page on the Azure dashboard and click the VM’s name in the Name column of the table.

    screenshot of Azure 'Virtual machines' page with list of VMs

  2. On the page that opens (ngx-plus-1 in this guide), note the VM’s public IP address (in the Public IP address field in the right column).

    screenshot of details page for 'ngx-plus-1' VM in Azure

  3. Run this command to establish an SSH connection to the VM:

    ssh -i <private-key-file> <username>@<public-IP-address>
    

    where

    • <private-key-file> is the name of the file containing the private key paired with the public key you entered in the SSH public key field in Step 4 of Creating a Microsoft Azure Virtual Machine.
    • <username> is the name you entered in the Username field in Step 4 of Creating a Microsoft Azure Virtual Machine (in this guide it is nginx_azure).
    • <public-IP-address> is the address you looked up in the previous step.

Installing NGINX Software

Once you have established a connection with an instance, you can install the NGINX software on it. Follow the instructions in the NGINX Plus Admin Guide for NGINX Open Source and NGINX Plus. The Admin Guide also provides instructions for many maintenance tasks.

Automating Installation with a Configuration Manager

You can automate the installation of NGINX Open Source and NGINX Plus. Instructions for Ansible are provided below. For Chef and Puppet, see these articles on the NGINX blog:

Automating Installation with Ansible

NGINX publishes a unified Ansible role for NGINX Open Source and NGINX Plus on Ansible Galaxy and GitHub. Perform these steps to install and run it.

  1. Connect to the VM.

  2. Install Ansible. These commands are appropriate for Debian and Ubuntu systems:

    apt update
    apt install python-pip -y
    pip install ansible
    
  3. Install the official Ansible role from NGINX:

    ansible-galaxy install nginxinc.nginx
    
  4. (NGINX Plus only) Copy the nginx-repo.key and nginx-repo.crt files provided by NGINX to ~/.ssh/ngx-certs/.

  5. Create a file called playbook.yml with the following contents:

    ---
    - hosts: localhost
      become: true
      roles:
        - role: nginxinc.nginx
    
  6. Run the playbook:

    ansible-playbook playbook.yml
    

Optional: Creating an NGINX Open Source Image

To streamline the process of installing NGINX Open Source on multiple VMs, you can create a Microsoft Azure image from an existing NGINX Open Source VM, and spin up additional instances of the image when needed.

  1. Install NGINX Open Source on the source VM, if you haven’t already.

  2. Navigate to the Virtual machines page, if you are not already there.

  3. In the list of VMs, click the name of the one to use as a source image (in this guide, we have called it ngx-oss). Remember that NGINX Open Source needs to be installed on it already.

  4. On the page than opens, click the Capture icon in the top navigation bar.

    screenshot of details page for 'nginx-oss' VM in Azure

  5. On the Create image page that opens, take note of the informational and warning banners and take any necessary action. Note in particular that if you use one of the VMs you created in Creating a Microsoft Azure Virtual Machine as the source for the image, you will need to re‑create a VM with that name.

    Then select the following values:

    • Name – Keep the current value.
    • Resource group – Select the appropriate resource group from the drop‑down menu. Here it is NGINX-Plus-HA.
    • Automatically delete this virtual machine after creating the image – We recommend checking the box, since you can’t do anything more with the image anyway.
    • Zone resiliency – On.
    • Type the virtual machine name – Name of the source VM (ngx-oss in this guide).

    Click the  Create  button.

    screenshot of Azure 'Create Image' page

Creating a VM from the Image

It takes a few moments for the image to be created. When it’s ready, you can create VMs from it with NGINX Open Source already installed.

  1. Navigate to the Images page. (One method is to type images in the search box in the Microsoft Azure header bar and select that value in the Services section of the resulting drop‑down menu.)

    screenshot of Azure 'Images' page

  2. Click the image name in the table. On the page that opens, click + Create VM in the top navigation bar.

    screenshot of details page for Azure 'ngx-plus-1-image' image

The Create a virtual machine page that opens is the same as in Step 4 of Creating a Microsoft Azure Virtual Machine, except that some fields have hardcoded values derived from the image and the Image field has the name of the image instead of an operating system. Return to that step to complete the VM creation.

Revision History

  • Version 1 (September 2020) – Initial version (NGINX Plus Release 22)

Last modified August 22, 2024