Mapping a custom domain (e.g., example.com or api.example.com) to an Azure Virtual Machine involves reserving a static IP address, opening network firewall ports, updating your DNS registrar records, and binding the web server.
Technical Overview & Prerequisites
User Request ──> https://api.yourdomain.com
│
▼ (DNS Registrar - A Record)
Azure Public IP (Static)
│
▼ (Network Security Group)
Ports 80/443 Open
│
▼ (Azure VM Web Server)
Nginx / IIS / Apache / Reverse Proxy
Azure Infrastructure: Linux or Windows Virtual Machine with a web server installed (Nginx, IIS, Apache, Kestrel).
Network Requirement: Static Public IPv4 Address.
DNS Registrar Access: Ability to edit DNS zone records (GoDaddy, Cloudflare, Namecheap, etc.).
Step 1: Ensure Your Azure Public IP is Static
By default, Azure public IP addresses may be dynamic, meaning the IP changes if the VM is stopped or deallocated. You must set it to Static so your DNS mappings remain permanent.
Log in to the Azure Portal.
Navigate to Virtual Machines and select your VM.
In the left menu under Settings, click Properties.
Click on your Public IP address.
On the Public IP page, click Configuration under Settings.
Set Assignment to Static.
(Optional) Under DNS name label, enter an alias prefix (e.g.,
myuniqueapp) to assign a default Azure FQDN (myuniqueapp.eastus.cloudapp.azure.com).Click Save at the top.
Copy your Public IP Address for use in Step 3.
Step 2: Configure Network Security Group (NSG) Rules
Ensure Azure allows incoming HTTP and HTTPS web traffic to reach your virtual machine.
On your VM's overview page in the Azure Portal, select Networking from the left menu.
Under Inbound port rules, check if rules for HTTP (Port 80) and HTTPS (Port 443) are present.
If missing, click Add inbound port rule and configure:
Source:
AnySource port ranges:
*Destination:
AnyService:
HTTP(Port 80) /HTTPS(Port 443)Action:
AllowPriority:
300(or any available low number)Name:
Allow-HTTP-HTTPS
Click Add.
Step 3: Add DNS Records at Your Domain Registrar
Log in to the DNS management dashboard provided by your registrar (e.g., GoDaddy, Namecheap, Cloudflare).
Scenario A: Mapping a Root Domain (yourdomain.com)
Add an A Record:
| Record Type | Host / Name | Value / Destination | TTL |
|---|---|---|---|
| A | @ | YOUR.AZURE.VM.IP | 600s / 1 Hour |
Add a CNAME Record for www:
Join the conversation! Your thoughts help the community grow.