You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在流量管理器+应用网关架构下配置CNAME记录

DNS Setup & Hostname Mapping for Your Azure Traffic Manager → App Gateway → Web Apps Flow

Let’s break down exactly how to configure your DNS records and map hostnames in the Azure Portal to get your architecture working smoothly.

First: Correct DNS Record Structure

Your setup requires two key DNS records (assuming you have a custom domain like yourdomain.com):

  • Primary custom domain (e.g., www.yourdomain.com): Create a CNAME record pointing to your Traffic Manager profile’s default domain (looks like your-tm-profile.trafficmanager.net). This sends all user traffic to Traffic Manager first for routing.
  • Subdomains for web apps (e.g., app1.yourdomain.com): Point these also to the Traffic Manager CNAME—this lets the Application Gateway handle host-based routing to your web apps.

Note: You don’t need the public-facing A record for your App Gateway’s IP to be used by end-users. Traffic Manager will route directly to your App Gateway resource (we’ll set that up next).

Step-by-Step Hostname Mapping in Azure Portal

First, ensure Traffic Manager is sending traffic to your App Gateway:

  • Open your Traffic Manager Profile in the Azure Portal.
  • Navigate to the Endpoints blade → Click Add.
  • Select Azure endpoint as the type, then pick your Application Gateway from the resource list (choose the correct subscription and resource group).
  • Set priority/weight based on your preferred routing method (e.g., priority for active-passive, weight for load balancing) → Save.

2. Configure App Gateway Listeners for Host-Based Routing

This is where you tell the App Gateway which hostnames to listen for (the ones pointed via CNAME to Traffic Manager):

  • Go to your Application Gateway → Open the Listeners blade.
  • Click Add listener:
    • Give it a descriptive name (e.g., Listener-WebApp1).
    • Select your public frontend IP (the one you created the A record for) as the frontend IP config.
    • Choose HTTP/HTTPS and the corresponding port (80 or 443).
    • Under Host type, pick Single host (for one hostname) or Multiple hosts (if routing to both web apps via different subdomains).
    • Enter the exact hostname (e.g., app1.yourdomain.com or www.yourdomain.com) you want to route.
  • Click Add, then repeat this to create a listener for WebApp2 (e.g., Listener-WebApp2 with app2.yourdomain.com).

3. Create Routing Rules to Redirect/Route to Web Apps

Now link those listeners to your web app backend pools:

  • In App Gateway, go to Rules → Click Add rule.
  • Choose Basic rule (ideal for host-based routing).
  • Name it (e.g., Rule-WebApp1), then select the listener you created for WebApp1.
  • For the Backend target, pick the backend pool that includes WebApp1 (create one if you haven’t already).
  • Select or create backend settings that match your web app’s protocol (HTTP/HTTPS, port, etc.). If you need to redirect instead of route directly, choose Redirect as the action and configure the target URL.
  • Save the rule, then repeat for WebApp2.

4. Register Custom Hostnames with Your Web Apps

Last critical step: Ensure your web apps recognize the custom hostnames to avoid 404s or routing errors:

  • Open each web app (WebApp1 and WebApp2) in the Azure Portal.
  • Go to Custom domains → Click Add custom domain.
  • Enter the hostname (e.g., app1.yourdomain.com), then click Validate.
  • Follow the prompts to add a TXT record in your DNS provider to prove ownership, then save the custom domain.

Verify the Flow

Once everything’s set up, traffic will flow like this:

  1. User visits app1.yourdomain.com (CNAME points to Traffic Manager).
  2. Traffic Manager routes the request to your Application Gateway.
  3. App Gateway matches the hostname to the Listener-WebApp1.
  4. The routing rule redirects/routes the request to WebApp1.

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:54:21