다음을 통해 공유


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

Important

Azure Front Door(클래식)는 2027년 3월 31일에 사용이 중지됩니다. 서비스가 중단되지 않도록 하려면 2027년 3월까지 Azure Front Door 표준 또는 프리미엄 계층으로 Azure Front Door(클래식) 프로필을 마이그레이션하는 것이 중요합니다. 자세한 내용은 Azure Front Door(클래식) 사용 중지를 참조하세요.

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

Important

이 스크립트를 사용하려면 도메인 이름에 대한 Azure DNS 공용 영역이 이미 있어야 합니다. 자습서는 Azure DNS에서 도메인 호스트를 참조하세요.

Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

사전 요구 사항

샘플 스크립트

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은 로그인한 초기 계정에서 자동으로 인증됩니다. 다음 스크립트를 통해 다른 구독을 사용하여 로그인하고 <Subscription ID>를 Azure 구독 ID로 바꿉니다. Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

subscription="<subscriptionId>" # add subscription 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

샘플 참조

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

명령 설명
az group create 모든 리소스가 저장되는 리소스 그룹을 만듭니다.
az storage account create 지정된 리소스 그룹에서 Azure Storage 계정을 만듭니다.
az storage blob service-properties update 스토리지 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 문서를 참조하세요.