Tutorial: Secure a web server with TLS/SSL certificates - Azure Virtual Machines (2024)

  • Article

Applies to: ✔️ Linux VMs

To secure web servers, a Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL), certificate can be used to encrypt web traffic. These TLS/SSL certificates can be stored in Azure Key Vault, and allow secure deployments of certificates to Linux virtual machines (VMs) in Azure. In this tutorial you learn how to:

  • Create an Azure Key Vault
  • Generate or upload a certificate to the Key Vault
  • Create a VM and install the NGINX web server
  • Inject the certificate into the VM and configure NGINX with a TLS binding

This tutorial uses the CLI within the Azure Cloud Shell, which is constantly updated to the latest version. To open the Cloud Shell, select Try it from the top of any code block.

If you choose to install and use the CLI locally, this tutorial requires that you're running the Azure CLI version 2.0.30 or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI.

Overview

Azure Key Vault safeguards cryptographic keys and secrets, such as certificates or passwords. Key Vault helps streamline the certificate management process and enables you to maintain control of keys that access those certificates. You can create a self-signed certificate inside Key Vault, or upload an existing, trusted certificate that you already own.

Rather than using a custom VM image that includes certificates baked-in, you inject certificates into a running VM. This process ensures that the most up-to-date certificates are installed on a web server during deployment. If you renew or replace a certificate, you don't also have to create a new custom VM image. The latest certificates are automatically injected as you create more VMs. During the whole process, the certificates never leave the Azure platform or are exposed in a script, command-line history, or template.

Create an Azure Key Vault

Before you can create a Key Vault and certificates, create a resource group with az group create. The following example creates a resource group named myResourceGroupSecureWeb in the eastus location:

az group create --name myResourceGroupSecureWeb --location eastus

Next, create a Key Vault with az keyvault create and enable it for use when you deploy a VM. Each Key Vault requires a unique name, and should be all lowercase. Replace <mykeyvault> in the following example with your own unique Key Vault name:

keyvault_name=<mykeyvault>az keyvault create \ --resource-group myResourceGroupSecureWeb \ --name $keyvault_name \ --enabled-for-deployment

Generate a certificate and store in Key Vault

For production use, you should import a valid certificate signed by trusted provider with az keyvault certificate import. For this tutorial, the following example shows how you can generate a self-signed certificate with az keyvault certificate create that uses the default certificate policy:

az keyvault certificate create \ --vault-name $keyvault_name \ --name mycert \ --policy "$(az keyvault certificate get-default-policy)"

Prepare a certificate for use with a VM

To use the certificate during the VM create process, obtain the ID of your certificate with az keyvault secret list-versions. Convert the certificate with az vm secret format. The following example assigns the output of these commands to variables for ease of use in the next steps:

secret=$(az keyvault secret list-versions \ --vault-name $keyvault_name \ --name mycert \ --query "[?attributes.enabled].id" --output tsv)vm_secret=$(az vm secret format --secrets "$secret" -g myResourceGroupSecureWeb --keyvault $keyvault_name)

Create a cloud-init config to secure NGINX

Cloud-init is a widely used approach to customize a Linux VM as it boots for the first time. You can use cloud-init to install packages and write files, or to configure users and security. As cloud-init runs during the initial boot process, there are no extra steps or required agents to apply your configuration.

When you create a VM, certificates and keys are stored in the protected /var/lib/waagent/ directory. To automate adding the certificate to the VM and configuring the web server, use cloud-init. In this example, you install and configure the NGINX web server. You can use the same process to install and configure Apache.

Create a file named cloud-init-web-server.txt and paste the following configuration:

#cloud-configpackage_upgrade: truepackages: - nginxwrite_files: - owner: www-data:www-data - path: /etc/nginx/sites-available/default content: | server { listen 443 ssl; ssl_certificate /etc/nginx/ssl/mycert.cert; ssl_certificate_key /etc/nginx/ssl/mycert.prv; }runcmd: - secretsname=$(find /var/lib/waagent/ -name "*.prv" | cut -c -57) - mkdir /etc/nginx/ssl - cp $secretsname.crt /etc/nginx/ssl/mycert.cert - cp $secretsname.prv /etc/nginx/ssl/mycert.prv - service nginx restart

Create a secure VM

Now create a VM with az vm create. The certificate data is injected from Key Vault with the --secrets parameter. You pass in the cloud-init config with the --custom-data parameter:

az vm create \ --resource-group myResourceGroupSecureWeb \ --name myVM \ --image Ubuntu2204 \ --admin-username azureuser \ --generate-ssh-keys \ --custom-data cloud-init-web-server.txt \ --secrets "$vm_secret"

It takes a few minutes for the VM to be created, the packages to install, and the app to start. When the VM has been created, take note of the publicIpAddress displayed by the Azure CLI. This address is used to access your site in a web browser.

To allow secure web traffic to reach your VM, open port 443 from the Internet with az vm open-port:

az vm open-port \ --resource-group myResourceGroupSecureWeb \ --name myVM \ --port 443

Test the secure web app

Now you can open a web browser and enter https://<publicIpAddress> in the address bar. Provide your own public IP address from the VM create process. Accept the security warning if you used a self-signed certificate:

Tutorial: Secure a web server with TLS/SSL certificates - Azure Virtual Machines (1)

Your secured NGINX site is then displayed as in the following example:

Tutorial: Secure a web server with TLS/SSL certificates - Azure Virtual Machines (2)

Next steps

In this tutorial, you secured an NGINX web server with a TLS/SSL certificate stored in Azure Key Vault. You learned how to:

  • Create an Azure Key Vault
  • Generate or upload a certificate to the Key Vault
  • Create a VM and install the NGINX web server
  • Inject the certificate into the VM and configure NGINX with a TLS binding

Follow this link to see pre-built virtual machine script samples.

Tutorial: Secure a web server with TLS/SSL certificates - Azure Virtual Machines (2024)

FAQs

How do I set TLS on Azure VM? ›

Navigate to your storage account in the Azure portal. Under Settings, select Configuration. Under Minimum TLS version, use the drop-down to select the minimum version of TLS required to access data in this storage account.

How to configure SSL certificate in Azure VM? ›

Follow these steps to install SSL certificate on Microsoft Azure and get https quickly.
  1. Step 1 – Add Custom Domain to Azure App Service. ...
  2. Step 2 – Add SSL Certificate to Azure Web App. ...
  3. Step 3 – Add SSL Certificate to Azure Cloud Service. ...
  4. Step 4 – Bind SSL Certificate to Website in IIS.

How TLS SSL Certificates secure a Web server? ›

TLS/SSL certificates secure internet connections by encrypting data sent between your browser, the website you're visiting, and the website server. They ensure that data is transmitted privately and without modifications, loss or theft.

How to secure a web server in Azure? ›

Create an Azure Key Vault. Generate or upload a certificate to the Key Vault. Create a VM and install the NGINX web server. Inject the certificate into the VM and configure NGINX with a TLS binding.

How to enable TLS on a Virtual Machine? ›

After you've created these keys, you need to create the Client and Server keys under them.
  1. For SSL3, select New > Key. Enter Client and press enter. Again, for SSL3, select New > Key again. Then enter Server and press Enter.
  2. Repeat the action to create the Client and Server keys under TLS 1.0, TLS 1.1, and TLS 1.2.
Jul 10, 2024

How to add an SSL certificate to a Virtual Machine? ›

Install an SSL Certificate
  1. Login into the SD-WAN Orchestrator CLI console through SSH. ...
  2. Generate the SD-WAN Orchestrator private key. ...
  3. Generate a certificate request. ...
  4. Send server. ...
  5. Install the certificate (which requires root access). ...
  6. Restart nginx.
Sep 14, 2020

How to secure a website using SSL certificate? ›

To use HTTPS with your domain name, you need a SSL or TLS certificate installed on your website. Your web host (Web Hosting Provider) may offer HTTPS security or you can request a SSL/TLS certificate from Certificate Authorities and install it yourself. SSL/TLS certificates may need to be renewed periodically.

What is the difference between SSL and TLS certificates? ›

SSL is technology your applications or browsers may have used to create a secure, encrypted communication channel over any network. However, SSL is an older technology that contains some security flaws. Transport Layer Security (TLS) is the upgraded version of SSL that fixes existing SSL vulnerabilities.

How to configure SSL certificate in web server? ›

Let's dive in!
  1. Step 1: Generate SSL Certificate. The first step is to generate a SSL certificate. ...
  2. Step 2: Configure Apache. ...
  3. Step 3: Enable SSL Module. ...
  4. Step 4: Enable SSL Virtual Host. ...
  5. Step 5: Restart Apache. ...
  6. Step 6: Verify SSL Configuration. ...
  7. Step 7: Test SSL Connection. ...
  8. Step 8: Renew SSL Certificate (Optional)
Feb 21, 2024

How do I secure my Azure virtual machine? ›

In this article, we'll walk through some fundamental steps to bolster the security of your Azure VMs.
  1. Regularly Update and Patch Your VMs. ...
  2. Implement Strong Authentication and Authorization. ...
  3. Utilize Network Security Groups and Firewalls. ...
  4. Enable Azure Security Center. ...
  5. Encrypt Your Data. ...
  6. Regularly Backup Your Data.
Jan 18, 2024

How do I enforce SSL connection in Azure? ›

Using the Azure portal

Visit your Azure Database for PostgreSQL server and select Connection security. Use the toggle button to enable or disable the Enforce SSL connection setting. Then, select Save. You can confirm the setting by viewing the Overview page to see the SSL enforce status indicator.

How can I make my web server more secure? ›

How to Keep Your Web Server Secure
  1. Eliminate Redundant Services. ...
  2. Control Remote Access. ...
  3. Distinguish Development and Production Environments. ...
  4. Isolate Web Application Data. ...
  5. Manage Permissions and Privileges. ...
  6. Install Security Patches. ...
  7. Monitor and Audit Server Logs. ...
  8. Secure User Accounts.
Jan 3, 2024

How do I enable TLS 1.2 in Azure? ›

Follow these steps:
  1. In the Azure portal, search for and select Microsoft Entra ID.
  2. In the Overview page menu, select Sign-in logs.
  3. Select a sign-in log entry for a user.
  4. Select the Additional details tab. ...
  5. Check for a Legacy TLS (TLS 1.0, 1.1, or 3DES) value that's set to True.
Apr 11, 2024

How to set TLS configuration? ›

Google Chrome
  1. Open Google Chrome.
  2. Click Alt F and select Settings.
  3. Scroll down and select Show advanced settings...
  4. Scroll down to the Network section and click on Change proxy settings...
  5. Select the Advanced tab.
  6. Scroll down to Security category, manually check the option box for Use TLS 1.1 and Use TLS 1.2.
  7. Click OK.
Nov 1, 2023

What is the default TLS version in Azure? ›

By default, the minimum TLS version for incoming requests to your web app and to SCM would be set to 1.2 on both portal and API.

How do I check my Azure storage TLS? ›

To determine the incoming TLS version for Azure Storage, you can enable logging for your Azure Storage account and analyze the logs after an interval of time to detect what versions of TLS client applications are using and you can use this MS-Document to monitor the storage.

Top Articles
Try It Tuesday: The "Buddha Diet" and Intermittent Fasting – Food Insight
What is PayPal Working Capital and how do I apply?
Scheelzien, volwassenen - Alrijne Ziekenhuis
Exclusive: Baby Alien Fan Bus Leaked - Get the Inside Scoop! - Nick Lachey
Ffxiv Palm Chippings
Chatiw.ib
Don Wallence Auto Sales Vehicles
South Park Season 26 Kisscartoon
Costco The Dalles Or
1movierulzhd.fun Reviews | scam, legit or safe check | Scamadviser
Blairsville Online Yard Sale
THE 10 BEST River Retreats for 2024/2025
Obituary Times Herald Record
Delectable Birthday Dyes
Valentina Gonzalez Leak
Check From Po Box 1111 Charlotte Nc 28201
Katherine Croan Ewald
Beebe Portal Athena
Spider-Man: Across The Spider-Verse Showtimes Near Marcus Bay Park Cinema
The best TV and film to watch this week - A Very Royal Scandal to Tulsa King
Zack Fairhurst Snapchat
Missed Connections Inland Empire
Drago Funeral Home & Cremation Services Obituaries
12 Top-Rated Things to Do in Muskegon, MI
Evil Dead Rise Showtimes Near Regal Sawgrass & Imax
Yosemite Sam Hood Ornament
Costco Gas Hours St Cloud Mn
Black Panther 2 Showtimes Near Epic Theatres Of Palm Coast
Broken Gphone X Tarkov
Homewatch Caregivers Salary
Boneyard Barbers
Frommer's Belgium, Holland and Luxembourg (Frommer's Complete Guides) - PDF Free Download
Murphy Funeral Home & Florist Inc. Obituaries
The Bold And The Beautiful Recaps Soap Central
Rage Of Harrogath Bugged
15 Best Things to Do in Roseville (CA) - The Crazy Tourist
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
R: Getting Help with R
Is Ameriprise A Pyramid Scheme
Nimbleaf Evolution
Swsnj Warehousing Inc
Large Pawn Shops Near Me
Hillsborough County Florida Recorder Of Deeds
Keci News
Lesson 5 Homework 4.5 Answer Key
antelope valley for sale "lancaster ca" - craigslist
Uno Grade Scale
The Missile Is Eepy Origin
Supervisor-Managing Your Teams Risk – 3455 questions with correct answers
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 6481

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.