在 Cloud Shell 中使用 Azure Resource Manager 範本 (ARM 範本) 和 Azure CLI 將應用程式部署至雲端,以開始使用 Azure App Service。 Resource Manager 範本是一個 JavaScript 物件標記法 (JSON) 檔案,會定義專案的基礎結構和設定。 因為您是使用免費的 App Service 層,所以您無需支付任何費用即可完成本快速入門。
若要完成本快速入門,您需要具備作用中訂用帳戶的 Azure 帳戶。 如果您沒有 Azure 帳戶,可以建立一個免費帳戶。
附註
從 ARM API 版本 2024-11-01 開始,網站預設情況下會停用基本驗證。 如果需要,用戶可以 手動啟用它 。
跳到結尾
如果您熟悉使用 ARM 範本,您可以選取此 按鈕來略過跳到結尾。 此按鈕會在 Azure 入口網站中開啟 ARM 範本。
在 Azure 入口網站中,選取 [建立新的] 以建立新的資源群組,然後選取 [檢閱 + 建立] 按鈕來部署應用程式。
在 Cloud Shell 中使用 Azure Resource Manager 範本 (ARM 範本) 和 Azure CLI 將應用程式部署至雲端,以開始使用 Azure App Service。 Resource Manager 範本是一個 JavaScript 物件標記法 (JSON) 檔案,會定義專案的基礎結構和設定。 因為您是使用免費的 App Service 層,所以您無需支付任何費用即可完成本快速入門。
若要完成本快速入門,您需要具備作用中訂用帳戶的 Azure 帳戶。 如果您沒有 Azure 帳戶,可以建立一個免費帳戶。
附註
從 ARM API 版本 2024-11-01 開始,網站預設情況下會停用基本驗證。 如果需要,用戶可以 手動啟用它 。
跳到結尾
如果您熟悉使用 ARM 範本,您可以選取此 按鈕來略過跳到結尾。 此按鈕會在 Azure 入口網站中開啟 ARM 範本。
在 Azure 入口網站中,選取 [建立新的] 以建立新的資源群組,然後選取 [檢閱 + 建立] 按鈕來部署應用程式。
在 Cloud Shell 中使用 Azure Resource Manager 範本 (ARM 範本) 和 Azure CLI 將應用程式部署至雲端,以開始使用 Azure App Service。 Resource Manager 範本是一個 JavaScript 物件標記法 (JSON) 檔案,會定義專案的基礎結構和設定。 部署 Windows 容器應用程式需要進階方案。 如需定價詳細資料,請參閱 App Service 定價頁面。
附註
從 ARM API 版本 2024-11-01 開始,網站預設情況下會停用基本驗證。 如果需要,用戶可以 手動啟用它 。
跳到結尾
如果您熟悉使用 ARM 範本,您可以選取此 按鈕來略過跳到結尾。 此按鈕會在 Azure 入口網站中開啟 ARM 範本。
在 Azure 入口網站中,選取 [建立新的] 以建立新的資源群組,然後選取 [檢閱 + 建立] 按鈕來部署應用程式。
檢閱範本
本快速入門中使用的範本是來自 Azure 快速入門範本。 其會在 Windows 上部署 App Service 方案和 App Service 應用程式。 其與 .NET Core、.NET Framework、PHP、Node.js 和靜態 HTML 應用程式相容。 若為 Java,請參閱建立 Java 應用程式。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "16144177164140676603"
}
},
"parameters": {
"webAppName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "Web app name."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"sku": {
"type": "string",
"defaultValue": "F1",
"metadata": {
"description": "The SKU of App Service Plan."
}
},
"language": {
"type": "string",
"defaultValue": ".net",
"allowedValues": [
".net",
"html"
],
"metadata": {
"description": "The language stack of the app."
}
},
"helloWorld": {
"type": "bool",
"defaultValue": false,
"metadata": {
"description": "true = deploy a sample Hello World app."
}
},
"repoUrl": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Optional Git Repo URL"
}
}
},
"variables": {
"appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]",
"gitRepoReference": {
".net": "https://github.com/Azure-Samples/app-service-web-dotnet-get-started",
"html": "https://github.com/Azure-Samples/html-docs-hello-world"
},
"gitRepoUrl": "[if(bool(parameters('helloWorld')), variables('gitRepoReference')[toLower(parameters('language'))], parameters('repoUrl'))]",
"configReference": {
".net": {
"comments": ".Net app. No additional configuration needed."
},
"html": {
"comments": "HTML app. No additional configuration needed."
}
}
},
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-01-01",
"name": "[variables('appServicePlanPortalName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('sku')]"
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"siteConfig": "[variables('configReference')[parameters('language')]]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
"httpsOnly": true
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
]
},
{
"condition": "[contains(variables('gitRepoUrl'), 'http')]",
"type": "Microsoft.Web/sites/sourcecontrols",
"apiVersion": "2023-01-01",
"name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
"properties": {
"repoUrl": "[variables('gitRepoUrl')]",
"branch": "master",
"isManualIntegration": true
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
]
}
]
}
範本中定義了兩個 Azure 資源:
- Microsoft.Web/serverfarms:建立 App Service 方案。
- Microsoft.Web/sites:建立 App Service 應用程式。
此範本包含數個為了讓您方便而預先定義的參數。 請參閱表格中的參數預設值和其描述:
| 參數 | 類型 | 預設值 | 描述 |
|---|---|---|---|
| webAppName | 字串 | webApp-<uniqueString> |
基於唯一字串值的應用程式名稱 |
| appServicePlanName | 字串 | webAppPlan-<uniqueString> |
基於唯一字串值的 App Service 方案名稱 |
| 位置 | 字串 | [resourceGroup().location] |
應用程式區域 |
| sku | 字串 | F1 |
執行個體大小 (F1 = 免費層) |
| 語言 | 字串 | .NET |
程式設計語言堆疊 (.NET、php、node、html) |
| helloWorld | boolean | False |
True = 部署 "Hello World" 應用程式 |
| repoUrl | 字串 | |
外部 Git 存放庫 (選擇性) |
本快速入門中使用的範本是來自 Azure 快速入門範本。 其會在 Linux 上部署 App Service 方案和 App Service 應用程式。 其與 App Service 上所有支援的程序設計語言相容。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.5.6.12127",
"templateHash": "10602523904429381366"
}
},
"parameters": {
"webAppName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "Web app name."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"sku": {
"type": "string",
"defaultValue": "F1",
"metadata": {
"description": "The SKU of App Service Plan."
}
},
"linuxFxVersion": {
"type": "string",
"defaultValue": "DOTNETCORE|8.0",
"metadata": {
"description": "The Runtime stack of current web app"
}
},
"repoUrl": {
"type": "string",
"defaultValue": " ",
"metadata": {
"description": "Optional Git Repo URL"
}
}
},
"variables": {
"appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]"
},
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2021-02-01",
"name": "[variables('appServicePlanPortalName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('sku')]"
},
"kind": "linux",
"properties": {
"reserved": true
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-02-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true,
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
"siteConfig": {
"linuxFxVersion": "[parameters('linuxFxVersion')]",
"minTlsVersion": "1.2",
"ftpsState": "FtpsOnly"
}
},
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
]
},
{
"condition": "[contains(parameters('repoUrl'), 'http')]",
"type": "Microsoft.Web/sites/sourcecontrols",
"apiVersion": "2021-02-01",
"name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
"properties": {
"repoUrl": "[parameters('repoUrl')]",
"branch": "master",
"isManualIntegration": true
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
]
}
]
}
範本中定義了兩個 Azure 資源:
- Microsoft.Web/serverfarms:建立 App Service 方案。
- Microsoft.Web/sites:建立 App Service 應用程式。
此範本包含數個為了讓您方便而預先定義的參數。 請參閱表格中的參數預設值和其描述:
| 參數 | 類型 | 預設值 | 描述 |
|---|---|---|---|
| webAppName | 字串 | webApp-<uniqueString> |
基於唯一字串值的應用程式名稱 |
| appServicePlanName | 字串 | webAppPlan-<uniqueString> |
基於唯一字串值的 App Service 方案名稱 |
| 位置 | 字串 | [resourceGroup().location] |
應用程式區域 |
| sku | 字串 | F1 |
執行個體大小 (F1 = 免費層) |
| linuxFxVersion | 字串 | DOTNETCORE|9.0 |
「程式設計語言堆疊 |版本」 |
| repoUrl | 字串 | |
外部 Git 存放庫 (選擇性) |
本快速入門中使用的範本是來自 Azure 快速入門範本。 其會在 Windows 容器上部署 App Service 方案和 App Service 應用程式。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "10193476814580854111"
}
},
"parameters": {
"appServiceWebAppName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "Web App name."
}
},
"appServicePlanName": {
"type": "string",
"defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
"minLength": 2,
"metadata": {
"description": "App Service Plan name."
}
},
"skuTier": {
"type": "string",
"defaultValue": "P1v3"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[parameters('appServiceWebAppName')]",
"location": "[parameters('location')]",
"tags": {
"[format('hidden-related:{0}', resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName')))]": "empty"
},
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "PORT",
"value": "8080"
}
],
"appCommandLine": "",
"windowsFxVersion": "DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp"
},
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
]
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-01-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('skuTier')]"
},
"kind": "windows",
"properties": {
"hyperV": true
}
}
]
}
範本中定義了兩個 Azure 資源:
- Microsoft.Web/serverfarms:建立 App Service 方案。
- Microsoft.Web/sites:建立 App Service 應用程式。
此範本包含數個為了讓您方便而預先定義的參數。 請參閱表格中的參數預設值和其描述:
| 參數 | 類型 | 預設值 | 描述 |
|---|---|---|---|
| webAppName | 字串 | webApp-<uniqueString> |
基於唯一字串值的應用程式名稱 |
| appServicePlanName | 字串 | webAppPlan-<uniqueString> |
基於唯一字串值的 App Service 方案名稱 |
| 位置 | 字串 | [resourceGroup().location] |
應用程式區域 |
| skuTier | 字串 | P1v3 |
執行個體大小 (檢視可用的 SKU) |
| appSettings | 字串 | [{"name": "PORT","value": "8080"}] |
App Service 接聽連接埠。 必須是 8080。 |
| kind | 字串 | windows |
作業系統 |
| hyperv | 字串 | true |
隔離模式 |
| windowsFxVersion | 字串 | DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp |
容器映像 |
部署範本
這裡使用 Azure CLI 來部署範本。 您也可以使用 Azure 入口網站、Azure PowerShell 和 REST API。 若要了解其他部署方法,請參閱部署範本。
下列程式碼會建立資源群組、App Service 方案和 Web 應用程式。 將為你設置預設資源組、應用服務計劃和位置。 請將 <app-name> 取代為全域唯一的應用程式名稱 (有效字元為 a-z、0-9 和 -)。
執行下列命令以在 Windows 上部署 .NET Framework 應用程式。
az group create --name myResourceGroup --location "southcentralus"
az deployment group create --resource-group myResourceGroup \
--parameters language=".NET" helloWorld="true" webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows/azuredeploy.json"
執行下列命令以在 Linux 上建立 Python 應用程式:
az group create --name myResourceGroup --location "southcentralus"
az deployment group create --resource-group myResourceGroup --parameters webAppName="<app-name>" linuxFxVersion="PYTHON|3.9" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-linux/azuredeploy.json"
若要部署不同的語言堆疊,請使用適當值更新 linuxFxVersion。 範例顯示在表格中。 若要顯示目前的版本,請在 Cloud Shell 中執行下列命令:
az webapp config show --resource-group myResourceGroup --name <app-name> --query linuxFxVersion
| 語言 | 範例 |
|---|---|
| .NET | linuxFxVersion=“DOTNETCORE|9.0” |
| 爪哇島 | linuxFxVersion=“JAVA|21-java21 TOMCAT|11.0-java21 JBOSSEAP|8-java17” |
| Node.js | linuxFxVersion="NODE|22-lts |
| Python(編程語言) | linuxFxVersion=“PYTHON|3.13” |
| PHP | linuxFxVersion=“PHP|8.4” |
執行下列命令以在 Windows 容器上部署 .NET 應用程式。
az group create --name myResourceGroup --location "southcentralus"
az deployment group create --resource-group myResourceGroup \
--parameters webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows-container/azuredeploy.json"
驗證部署
瀏覽至 http://<app_name>.azurewebsites.net/ 並確認已建立好。
清除資源
當不再需要時,請刪除資源群組。