使用流量管理員整合在 Azure App Service 中設定自訂功能變數名稱Configure a custom domain name in Azure App Service with Traffic Manager integration

當您使用Azure 流量管理員Azure App Service的流量進行負載平衡時,可使用** <traffic-manager-endpoint> trafficmanager.net**存取 App Service 應用程式。When you use Azure Traffic Manager to load balance traffic to Azure App Service, the App Service app can be accessed using <traffic-manager-endpoint>.trafficmanager.net. 您可以使用 App Service 應用程式指派自訂功能變數名稱,例如 www . contoso.com,以便為您的使用者提供更容易辨識的功能變數名稱。You can assign a custom domain name, such as www.contoso.com, with your App Service app in order to provide a more recognizable domain name for your users.

本文說明如何使用與 流量管理員整合的 App Service 應用程式來設定自訂功能變數名稱。This article shows you how to configure a custom domain name with an App Service app that's integrated with Traffic Manager.

注意

當您使用流量管理員端點設定功能變數名稱時,僅支援 CNAME 記錄。Only CNAME records are supported when you configure a domain name using the Traffic Manager endpoint. 由於不支援記錄,因此也不支援根域對應(例如 contoso.com)。Because A records are not supported, a root domain mapping, such as contoso.com is also not supported.

準備應用程式Prepare the app

若要將自訂 DNS 名稱對應至與 Azure 流量管理員整合的應用程式,web 應用程式的 App Service 方案 必須是 標準 層或更高的版本。To map a custom DNS name to an app that's integrated with Azure Traffic Manager, the web app's App Service plan must be in Standard tier or higher. 在此步驟中,您要確定 App Service 應用程式位於支援的定價層。In this step, you make sure that the App Service app is in the supported pricing tier.

檢查定價層Check the pricing tier

Azure 入口網站中,搜尋並選取 [ 應用程式服務]。In the Azure portal, search for and select App Services.

在 [應用程式服務] 頁面上,選取您的 Azure 應用程式名稱。On the App Services page, select the name of your Azure app.

入口網站瀏覽至 Azure 應用程式

在 [應用程式] 頁面的左側導覽中,選取 [ **擴大 (] App Service 方案) **。In the left navigation of the app page, select Scale up (App Service plan).

相應增加功能表

會以藍色框線醒目顯示應用程式目前的層。The app's current tier is highlighted by a blue border. 請檢查以確定應用程式位於 標準 層或更高版本, (生產隔離 類別) 中的任何層。Check to make sure that the app is in Standard tier or above (any tier in the Production or Isolated category). 如果是,請關閉 [ 擴大 ] 頁面,並略過 建立 CNAME 對應If yes, close the Scale up page and skip to Create the CNAME mapping.

檢查定價層

擴大 App Service 方案Scale up the App Service plan

如果您需要擴大您的應用程式,請選取 [ 生產 ] 類別中的任何定價層。If you need to scale up your app, select any of the pricing tiers in the Production category. 如需其他選項,請按一下 [查看其他選項]。For additional options, click See additional options.

按一下 [套用]。Click Apply.

建立流量管理員端點Create Traffic Manager endpoint

遵循 新增或刪除端點的步驟,將您的 App Service 應用程式新增為流量管理員設定檔中的端點。Following the steps at Add or Delete Endpoints, add your App Service app as an endpoint in your Traffic Manager profile.

一旦您的 App Service 應用程式在支援的定價層中,當您新增端點時,它會顯示在可用的 App Service 目標清單中。Once your App Service app is in a supported pricing tier, it shows up in the list of available App Service targets when you add the endpoint. 如果未列出您的應用程式,請 確認您應用程式的定價層If your app isn't listed, verify the pricing tier of your app.

建立 CNAME 對應Create the CNAME mapping

注意

若要設定 您所購買的 App Service 網域,請略過本節並移至 [ 啟用自訂網域]。To configure an App Service domain that you purchased, skip this section and go to Enable custom domain.

注意

您可以使用 Azure DNS 來設定 Azure App Service 的自訂 DNS 名稱。You can use Azure DNS to configure a custom DNS name for Azure App Service. 如需詳細資訊,請參閱使用 Azure DNS 為 Azure 服務提供自訂網域設定For more information, see Use Azure DNS to provide custom domain settings for an Azure service.

  1. 登入網域提供者的網站。Sign in to the website of your domain provider.

  2. 尋找管理 DNS 記錄的頁面。Find the page for managing DNS records. 每個網域提供者有自己的 DNS 記錄介面,請查閱您的提供者文件。Every domain provider has its own DNS records interface, so consult the provider's documentation. 在網站中尋找標示為 [網域名稱] 、[DNS] 或 [名稱伺服器管理] 的區域。Look for areas of the site labeled Domain Name, DNS, or Name Server Management.

    通常可透過檢視您的帳戶資訊,然後尋找 [我的網域] 之類的連結,來找到 DNS 記錄分頁。Often, you can find the DNS records page by viewing your account information and then looking for a link such as My domains. 移至該分頁,然後尋找名為區域檔案DNS 記錄進階設定之類的連結。Go to that page, and then look for a link that's named something like Zone file, DNS Records, or Advanced configuration.

    下列螢幕擷取畫面是 DNS 記錄頁面的範例:The following screenshot is an example of a DNS records page:

    顯示範例 DNS 記錄頁面的螢幕擷取畫面。

  3. 在螢幕擷取畫面範例中,選取 [新增] 以建立記錄。In the example screenshot, select Add to create a record. 某些提供者有不同的連結來新增其他記錄類型。Some providers have different links to add different record types. 同樣地,請參閱提供者的文件。Again, consult the provider's documentation.

注意

對於某些提供者 (例如 GoDaddy),您必須選取另外的 [儲存變更] 連結,才會讓 DNS 記錄的變更生效。For certain providers, such as GoDaddy, changes to DNS records don't become effective until you select a separate Save Changes link.

雖然每個網域提供者的細節各有不同,但您會非根自訂 (功能變數名稱(例如www.contoso.com) )對應與您的應用程式整合 (的流量管理員功能變數名稱contoso.trafficmanager.net) 。While the specifics of each domain provider vary, you map from a non-root custom domain name (such as www.contoso.com) to the Traffic Manager domain name (contoso.trafficmanager.net) that's integrated with your app.

注意

如果記錄已在使用中,而您需要事先將您的應用程式繫結到該記錄,您可以建立其他的 CNAME 記錄。If a record is already in use and you need to preemptively bind your apps to it, you can create an additional CNAME record. 例如,若要事先將 www . contoso.com 系結至您的應用程式,請建立從 AWVERIFYcontoso.trafficmanager.net的 CNAME 記錄。For example, to preemptively bind www.contoso.com to your app, create a CNAME record from awverify.www to contoso.trafficmanager.net. 然後,您可以將 "www . contoso.com" 新增至您的應用程式,而不需要變更 "www" CNAME 記錄。You can then add "www.contoso.com" to your app without the need to change the "www" CNAME record. 如需詳細資訊,請參閱 將 ACTIVE DNS 名稱遷移至 Azure App ServiceFor more information, see Migrate an active DNS name to Azure App Service.

在網域提供者處完成 DNS 記錄的新增或修改後,請儲存變更。Once you have finished adding or modifying DNS records at your domain provider, save the changes.

根域呢?What about root domains?

因為流量管理員僅支援使用 CNAME 記錄進行自訂網域對應,且 DNS 標準不支援對應根域的 CNAME 記錄 (例如, contoso.com) ,流量管理員不支援對應至根域。Since Traffic Manager only supports custom domain mapping with CNAME records, and because DNS standards don't support CNAME records for mapping root domains (for example, contoso.com), Traffic Manager doesn't support mapping to root domains. 若要解決此問題,請使用應用層級的 URL 重新導向。To work around this issue, use a URL redirect from at the app level. 例如,在 ASP.NET Core 中,您可以使用 URL 重寫In ASP.NET Core, for example, you can use URL Rewriting. 然後,使用流量管理員來平衡子域 (www.contoso.com) 的負載。Then, use Traffic Manager to load balance the subdomain (www.contoso.com).

在高可用性案例中,您可以建立多個從根域指向每個應用程式複本 IP 位址的 記錄 ,以在不使用流量管理員的情況下執行容錯 DNS 設定。For high availability scenarios, you can implement a fault-tolerant DNS setup without Traffic Manager by creating multiple A records that point from the root domain to each app copy's IP address. 然後,將 相同的根域對應至所有應用程式複本Then, map the same root domain to all the app copies. 因為相同的功能變數名稱無法對應到相同區域中的兩個不同應用程式,所以只有當您的應用程式複本位於不同區域時,此設定才會運作。Since the same domain name cannot be mapped to two different apps in the same region, this setup only works when your app copies are in different regions.

啟用自訂網域Enable custom domain

在您的功能變數名稱記錄傳播之後,請使用瀏覽器來確認您的自訂功能變數名稱會解析成您的 App Service 應用程式。After the records for your domain name have propagated, use the browser to verify that your custom domain name resolves to your App Service app.

注意

需要一些時間,CNAME 才能傳播至整個 DNS 系統。It can take some time for your CNAME to propagate through the DNS system. 您可以使用之類的服務 https://www.digwebinterface.com/ 來驗證 CNAME 是否可用。You can use a service such as https://www.digwebinterface.com/ to verify that the CNAME is available.

  1. 一旦網域解析成功之後,回到Azure 入口網站中的應用程式頁面Once domain resolution succeeds, to back to your app page in the Azure Portal

  2. 從左側導覽中,選取 [自訂網域 > 新增主機名稱]。From the left navigation, select Custom domains > Add hostname.

  3. 輸入您稍早對應的自訂功能變數名稱,然後選取 [ 驗證]。Type the custom domain name that you mapped earlier and select Validate.

  4. 確定 [主機名稱記錄類型] 已設定為 [CNAME (www.example.com 或任何子網域)]。Make sure that Hostname record type is set to CNAME (www.example.com or any subdomain).

  5. 由於 App Service 應用程式現在已與流量管理員端點整合,因此您應該會在 [ CNAME設定] 下看到流量管理員功能變數名稱。Since the App Service app is now integrated with a Traffic Manager endpoint, you should see the Traffic Manager domain name under CNAME configuration. 選取它,然後按一下 [ 新增自訂網域]。Select it and click Add custom domain.

    將 DNS 名稱新增至應用程式

後續步驟Next steps