다음을 통해 공유


Azure Front Door: 사용자 지정 도메인 배포

적용 대상: ✔️ Front Door(클래식)

Important

  • 2025년 8월 15일부터 Azure Front Door(클래식)는 더 이상 새로운 도메인 온보딩을 지원하지 않습니다. AFD 표준 및 프리미엄으로 마이그레이션하여 새 도메인 또는 프로필을 만들고 서비스 중단을 방지합니다.  자세히 알아보기

이 Azure CLI 스크립트 예제에서는 Azure Front Door 프런트 엔드에 사용자 지정 도메인 이름 및 TLS 인증서를 배포하는 방법을 보여 줍니다. 이 스크립트는 사용자 지정 도메인 이름(Azure DNS에서 호스팅됨) 및 TLS 인증서를 사용하여 Azure Front Door의 완전히 자동화된 프로비저닝을 보여 줍니다.

Important

도메인 이름에 대한 Azure DNS 공용 영역이 이미 있는지 확인합니다. 자습서는 Azure DNS에서 도메인 호스트를 참조하세요.

Azure 계정이 없는 경우 시작하기 전에 체험 계정을 만듭니다.

Prerequisites

샘플 스크립트

Azure Cloud Shell 시작

Azure Cloud Shell은 이 항목의 단계를 실행하는 데 무료로 사용할 수 있는 대화형 셸입니다. 공용 Azure 도구가 사전 설치되어 계정에서 사용하도록 구성되어 있습니다.

Cloud Shell을 열려면 코드 블록의 오른쪽 위 모서리에 있는 사용해 보세요를 선택하기만 하면 됩니다. 또한 https://shell.azure.com로 이동하여 별도의 브라우저 탭에서 Cloud Shell을 시작할 수 있습니다.

Cloud Shell이 열리면 환경에 대해 Bash가 선택되어 있는지 확인합니다. 후속 세션은 Bash 환경에서 Azure CLI를 사용합니다. 복사를 선택하여 코드 블록을 복사하고 Cloud Shell에 붙여넣고 Enter 키를 눌러 실행합니다.

Azure에 로그인

Cloud Shell은 로그인한 초기 계정에서 자동으로 인증됩니다. 다음 스크립트를 사용하여 다른 구독을 사용하여 로그인하고 subscriptionId를 Azure 구독 ID로 바꿉니다.

Azure 계정이 없는 경우 시작하기 전에 체험 계정을 만듭니다.

subscription="subscriptionId" # Set Azure subscription ID here

az account set -s $subscription # ...or use 'az login'

자세한 내용은 활성 구독 설정 또는 대화형으로 로그인을 참조하세요.

시작하기

스크립트는 다음을 수행합니다.

  1. 리소스 그룹을 만듭니다.
  2. SPA(단일 페이지 애플리케이션)를 호스트하는 스토리지 계정을 만듭니다.
  3. 스토리지 계정에서 SPA 호스팅을 사용하도록 설정합니다.
  4. "Hello world!" index.html 파일 업로드.
  5. Front Door 프로필 만들기.
  6. Front Door로 확인되는 Apex에 대한 DNS 별칭을 만듭니다.
  7. adverify 호스트 이름에 대한 CNAME 만들기
  8. 사용자 지정 도메인에 대한 Front Door 프런트 엔드 엔드포인트 만들기
  9. 사용자 지정 도메인 프런트 엔드에서 SPA 원본으로 경로를 추가합니다.
  10. HTTP를 HTTPS로 리디렉션하는 회람 규칙을 추가합니다.
  11. Front Door 관리 인증서를 사용하여 HTTPS를 사용하도록 설정합니다.

스크립트 실행

이 스크립트를 실행하려면 다음 코드를 .sh 파일에 복사하고, 하드 코드된 변수를 도메인 값으로 변경한 다음, 다음 명령을 실행하여 이러한 변수를 스크립트에 전달합니다.

AZURE_DNS_ZONE_NAME=www.contoso.com AZURE_DNS_ZONE_RESOURCE_GROUP=contoso-rg ./deploy-custom-apex-domain.sh
# Deploy a Custom Domain name and TLS certificate at the apex (root) on an Azure Front Door front-end.

# VARIABLES
# Change these hardcoded values if required

let "randomIdentifier=$RANDOM*$RANDOM"

# Use resource group environment variable if set
if [ "$RESOURCE_GROUP" == '' ];  
    then
        resourceGroup="msdocs-frontdoor-rg-$randomIdentifier"
    else
        resourceGroup="${RESOURCE_GROUP}"
fi

location='AustraliaEast'
tag='deploy-custom-domain'

storage="msdocsafd$randomIdentifier"

frontDoor="msdocs-frontdoor-$randomIdentifier"
frontDoorFrontEnd='www-contoso'

ttl=300

if [ "$AZURE_DNS_ZONE_NAME" == '' ]; 
   then 
        echo -e "\033[33mAZURE_DNS_ZONE_NAME environment variable is not set. Front Door will be created but custom frontend will not be configured because custom domain name not provided. Try:\n\n    AZURE_DNS_ZONE_NAME=www.contoso.com AZURE_DNS_ZONE_RESOURCE_GROUP=contoso-dns-rg ./deploy-custom-apex-domain.sh\n\nSee Readme for details.\033[0m"
   else     
        if [ "$AZURE_DNS_ZONE_RESOURCE_GROUP" == '' ]; 
            then 
                # write error text
                echo -e "\033[31mAZURE_DNS_ZONE_RESOURCE_GROUP environment variable is not set. Provide the resource group for the Azure DNS Zone. Try:\n\n    AZURE_DNS_ZONE_NAME=www.contoso.com AZURE_DNS_ZONE_RESOURCE_GROUP=contoso-dns-rg ./deploy-custom-apex-domain.sh\n\nSee Readme for details.\033[0m"
                
                # write stderr and exit
                >&2 echo "AZURE_DNS_ZONE_RESOURCE_GROUP environment variable is not set."
                exit 1
    fi
fi

# Resource group
az group create -n $resourceGroup -l $location --tags $tag


# STORAGE ACCOUNT
az storage account create -n $storage -g $resourceGroup -l $location --sku Standard_LRS --kind StorageV2

# Make Storage Account a SPA
az storage blob service-properties update --account-name $storage --static-website \
    --index-document 'index.html' --404-document 'index.html' 

# Upload index.html
az storage blob upload --account-name $storage -f ./index.html -c '$web' -n 'index.html' --content-type 'text/html'

# Get the URL to use as the origin URL on the Front Door backend
spaFQUrl=$( az storage account show -n $storage --query 'primaryEndpoints.web' -o tsv )

# Remove 'https://' and trailing '/'
spaUrl=${spaFQUrl/https:\/\//} ; spaUrl=${spaUrl/\//}


# FRONT DOOR
frontDoorId=$( az network front-door create -n $frontDoor -g $resourceGroup --tags $tag --accepted-protocols Http Https --backend-address $spaUrl --query 'id' -o tsv )


if [ "$AZURE_DNS_ZONE_NAME" != '' ]; 
   then 

    # AZURE DNS
    # Apex hostname on contoso.com
    # Create an Alias DNS recordset
    az network dns record-set a create -n "@" -g $AZURE_DNS_ZONE_RESOURCE_GROUP --zone-name $AZURE_DNS_ZONE_NAME --target-resource $frontDoorId --ttl $ttl

    # Create the domain verify CNAME
    az network dns record-set cname set-record -g $AZURE_DNS_ZONE_RESOURCE_GROUP --zone-name $AZURE_DNS_ZONE_NAME --record-set-name "afdverify" --cname "afdverify.$frontDoor.azurefd.net" --ttl $ttl


    # FRONT DOOR FRONT END
    # Create a frontend for the custom domain
    az network front-door frontend-endpoint create --front-door-name $frontDoor --host-name $AZURE_DNS_ZONE_NAME \
        --name $frontDoorFrontEnd -g $resourceGroup --session-affinity-enabled 'Disabled'

    # Update the default routing rule to include the new frontend
    az network front-door routing-rule update --front-door-name $frontDoor -n 'DefaultRoutingRule' -g $resourceGroup \
        --caching 'Enabled' --accepted-protocols 'Https' \
        --frontend-endpoints 'DefaultFrontendEndpoint' $frontDoorFrontEnd

    # Create http redirect to https routing rule
    az network front-door routing-rule create -f $frontDoor -g $resourceGroup -n 'httpRedirect' \
        --frontend-endpoints $frontDoorFrontEnd --accepted-protocols 'Http' --route-type 'Redirect' \
        --patterns '/*' --redirect-protocol 'HttpsOnly'

    # Update the default routing rule to include the new frontend
    az network front-door routing-rule update --front-door-name $frontDoor -n 'DefaultRoutingRule' -g $resourceGroup \
        --caching 'Enabled' --frontend-endpoints 'DefaultFrontendEndpoint' $frontDoorFrontEnd


    # Enable HTTPS. This command will return quickly but provisioning can take up to an hour to complete
    az network front-door frontend-endpoint enable-https \
        --front-door-name $frontDoor -n $frontDoorFrontEnd -g $resourceGroup
fi

리소스 정리

다음 명령을 사용하여 이러한 리소스가 계속해서 필요한 경우가 아니면 az group delete 명령을 사용하여 리소스 그룹 및 연결된 모든 리소스를 제거합니다. 이러한 리소스 중 일부는 만들고 삭제하는 데 시간이 걸릴 수 있습니다.

az group delete --name $resourceGroup

예시 참조

이 스크립트는 다음 명령을 사용합니다. 표에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

Command Description
az 그룹 생성 모든 리소스를 저장할 리소스 그룹을 만듭니다.
az storage account create 명령어로 스토리지 계정을 생성합니다. 지정된 리소스 그룹에서 Azure Storage 계정을 만듭니다.
az storage blob 서비스 속성 업데이트 스토리지 Blob 서비스 속성을 업데이트합니다.
az storage blob upload 컨테이너에 Blob을 업로드합니다.
az storage account show (스토리지 계정 보기) 스토리지 계정 속성을 표시합니다.
az network front-door create 명령어는 네트워크 프론트 도어를 생성합니다. Front Door을 만듭니다.
az network dns record-set DNS 레코드 및 레코드 집합을 관리합니다.
az network front-door Front Door을 관리합니다.

다음 단계

Azure CLI에 대한 자세한 내용은 Azure CLI 문서를 참조하세요.