您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在 Azure 应用服务中配置 Web 应用Configure web apps in Azure App Service

本主题介绍如何使用 Azure 门户配置 Web 应用。This topic explains how to configure a web app using the [Azure Portal].

备注

尽管本文中指的是 Web 应用,但内容同样适用于 API 应用和移动应用。Although this article refers to web apps, it also applies to API apps and mobile apps.

应用程序设置Application settings

  1. Azure 门户中,打开 Web 应用的边栏选项卡。In the [Azure Portal], open the blade for the web app.
  2. 单击“应用程序设置” 。Click Application settings.

应用程序设置

“应用程序设置”边栏选项卡包含多个类别的设置。The Application settings blade has settings grouped under several categories.

常规设置General settings

框架版本Framework versions. 如果应用程序使用下列任一框架,请设置这些选项:Set these options if your app uses any these frameworks:

  • .NET Framework:设置 .NET Framework 版本。.NET Framework: Set the .NET framework version.
  • PHP:设置 PHP 版本或设为“关”以禁用 PHP。PHP: Set the PHP version, or OFF to disable PHP.
  • Java:选择 Java 版本或设为“关”以禁用 Java。Java: Select the Java version or OFF to disable Java. 利用“Web 容器”选项来选择 Tomcat 或 Jetty 版本。Use the Web Container option to choose between Tomcat and Jetty versions.
  • Python:选择 Python 版本,或设为“关闭”以禁用 Python。Python: Select the Python version, or OFF to disable Python.

出于技术原因,为应用启用 Java 会禁用 .NET、PHP 和 Python 选项。For technical reasons, enabling Java for your app disables the .NET, PHP, and Python options.

平台Platform. 选择是要在 32 位还是 64 位环境中运行 Web 应用。Selects whether your web app runs in a 32-bit or 64-bit environment. 64 位环境需要“基本”或“标准”模式。The 64-bit environment requires Basic or Standard mode. “免费”和“共享”模式始终在 32 位环境下运行。Free and Shared modes always run in a 32-bit environment.

备注

应用服务免费和共享(预览)托管计划是基本层,与其他应用服务应用在相同的 Azure VM 上运行。App Service Free and Shared (preview) hosting plans are base tiers that run on the same Azure VM as other App Service apps. 某些应用可能属于其他客户。Some apps may belong to other customers. 这些层仅旨在用于开发和测试目的。These tiers are intended to be used only for development and testing purposes.

Web 套接字Web Sockets. 设为“开”以启用 WebSocket 协议;例如,如果 Web 应用使用 ASP.NET SignalRsocket.ioSet ON to enable the WebSocket protocol; for example, if your web app uses ASP.NET SignalR or socket.io.

始终打开Always On. 默认情况下,Web 应用如果已处于空闲状态相当一段时间,则是未加载的状态。By default, web apps are unloaded if they are idle for some period of time. 这样可以让系统节省资源。This lets the system conserve resources. 在“基本”或“标准”模式下,可启用“始终打开”以保证始终加载应用。In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. 如果你的应用运行连续的 Web 作业或运行使用 CRON 表达式触发的 Web 作业,应启用“始终打开”;否则这些 Web 作业可能无法可靠运行。If your app runs continuous WebJobs or runs WebJobs triggered using a CRON expression, you should enable Always On, or the web jobs may not run reliably.

托管管道版本Managed Pipeline Version. 设置 IIS 管道模式Sets the IIS [pipeline mode]. 将此设置保留为“集成(默认)”,除非旧版应用需要旧版 IIS。Leave this set to Integrated (the default) unless you have a legacy app that requires an older version of IIS.

自动交换Auto Swap. 如果启用部署槽的自动交换,则在向该槽推送更新时,应用服务会自动将 Web 应用交换到生产。If you enable Auto Swap for a deployment slot, App Service will automatically swap the web app into production when you push an update to that slot. 有关详细信息,请参阅为 Azure 应用服务中的 Web 应用部署到过渡槽For more information, see Deploy to staging slots for web apps in Azure App Service.

调试Debugging

远程调试Remote Debugging. 启用远程调试。Enables remote debugging. 启用后,可使用 Visual Studio 中的远程调试器直接连接到 Web 应用。When enabled, you can use the remote debugger in Visual Studio to connect directly to your web app. 远程调试将保持启用状态 48 小时。Remote debugging will remain enabled for 48 hours.

应用设置App settings

本部分包含 Web 应用启动时会要加载的名称/值对。This section contains name/value pairs that your web app will load on start up.

  • 对于 .NET 应用,这些设置=会在运行时注入到 .NET 配置 AppSettings 中,重写现有设置。For .NET apps, these settings are injected into your .NET configuration AppSettings at runtime, overriding existing settings.
  • PHP、Python、Java 和 Node 应用程序可以在运行时以环境变量的形式访问这些设置。PHP, Python, Java and Node applications can access these settings as environment variables at runtime. 系统将为每个应用程序设置创建两个环境变量,一个变量具有由应用程序设置条目指定的名称,另一个具有 APPSETTING_ 前缀。For each app setting, two environment variables are created; one with the name specified by the app setting entry, and another with a prefix of APPSETTING_. 这两个变量都包含相同的值。Both contain the same value.

连接字符串Connection strings

链接资源的连接字符串。Connection strings for linked resources.

对于 .NET 应用,这些连接字符串会在运行时注入到 .NET 配置 connectionStrings 设置中,重写其中的键等于链接的数据库名称的所有现有条目。For .NET apps, these connection strings are injected into your .NET configuration connectionStrings settings at runtime, overriding existing entries where the key equals the linked database name.

对于 PHP、Python、Java 和 Node 应用程序,这些设置会在运行时作为环境变量提供,并且用连接类型作为前缀。For PHP, Python, Java and Node applications, these settings will be available as environment variables at runtime, prefixed with the connection type. 下面列出了环境变量前缀:The environment variable prefixes are as follows:

  • SQL Server:SQLCONNSTR_SQL Server: SQLCONNSTR_
  • MySQL:MYSQLCONNSTR_MySQL: MYSQLCONNSTR_
  • SQL 数据库:SQLAZURECONNSTR_SQL Database: SQLAZURECONNSTR_
  • 自定义:CUSTOMCONNSTR_Custom: CUSTOMCONNSTR_

例如,如果 MySql 连接字符串命名为 connectionstring1,则会通过环境变量 MYSQLCONNSTR_connectionString1 访问该字符串。For example, if a MySql connection string were named connectionstring1, it would be accessed through the environment variable MYSQLCONNSTR_connectionString1.

默认文档Default documents

默认文档是网站的根 URL 下显示的网页。The default document is the web page that is displayed at the root URL for a website. 使用的是列表中的第一个匹配文件。The first matching file in the list is used.

Web 应用可能会使用根据 URL 路由的模块,而不是提供静态内容,在此情况下,将没有此类默认文档。Web apps might use modules that route based on URL, rather than serving static content, in which case there is no default document as such.

处理程序映射Handler mappings

使用此区域可添加自定义脚本处理器,以处理特定文件扩展名的请求。Use this area to add custom script processors to handle requests for specific file extensions.

  • 扩展名Extension. 要处理的扩展名,例如 *.php 或 handler.fcgi。The file extension to be handled, such as *.php or handler.fcgi.
  • 脚本处理器路径Script Processor Path. 脚本处理器的绝对路径。The absolute path of the script processor. 匹配该扩展名的文件请求由脚本处理器处理。Requests to files that match the file extension will be processed by the script processor. 使用路径 D:\home\site\wwwroot 表示应用的根目录。Use the path D:\home\site\wwwroot to refer to your app's root directory.
  • 其他参数Additional Arguments. 脚本处理器的可选命令行参数Optional command-line arguments for the script processor

虚拟应用程序和目录Virtual applications and directories

若要配置虚拟应用程序和目录,请指定每个虚拟目录及其对应于网站根目录的物理路径。To configure virtual applications and directories, specify each virtual directory and its corresponding physical path relative to the website root. 还可选中“应用程序”复选框,将虚拟目录标记为应用程序。Optionally, you can select the Application checkbox to mark a virtual directory as an application.

启用诊断日志Enabling diagnostic logs

启用诊断日志:To enable diagnostic logs:

  1. 在 Web 应用的边栏选项卡上单击“所有设置”。In the blade for your web app, click All settings.
  2. 单击“诊断日志”。Click Diagnostic logs.

从支持日志记录的 Web 应用程序写入诊断日志的选项:Options for writing diagnostic logs from a web application that supports logging:

  • 应用程序日志记录Application Logging. 将应用程序日志写入文件系统。Writes application logs to the file system. 日志记录将持续 12 小时。Logging lasts for a period of 12 hours.

级别Level. 启用应用程序日志记录时,此选项指定要记录的信息量(“错误”、“警告”、“信息”或“详细”)。When application logging is enabled, this option specifies the amount of information that will be recorded (Error, Warning, Information, or Verbose).

Web 服务器日志记录Web server logging. 日志以 W3C 扩展日志文件格式保存。Logs are saved in the W3C extended log file format.

详细的错误消息Detailed error messages. 保存详细的错误消息 .htm 文件。Saves detailed error messages .htm files. 文件保存在 /LogFiles/DetailedErrors 下。The files are saved under /LogFiles/DetailedErrors.

失败请求跟踪Failed request tracing. 将失败请求记录到 XML 文件中。Logs failed requests to XML files. 这些文件保存在 /LogFiles/W3SVCxxx 下,其中 xxx 是唯一标识符。The files are saved under /LogFiles/W3SVCxxx, where xxx is a unique identifier. 此文件夹包含一个 XSL 文件和一个或多个 XML 文件。This folder contains an XSL file and one or more XML files. 请务必下载 XSL 文件,因为 XSL 文件提供格式化和筛选 XML 文件内容的功能。Make sure to download the XSL file, because it provides functionality for formatting and filtering the contents of the XML files.

若要查看日志文件,必须按以下方式创建 FTP 凭据:To view the log files, you must create FTP credentials, as follows:

  1. 在 Web 应用的边栏选项卡上单击“所有设置”。In the blade for your web app, click All settings.
  2. 单击“部署凭据”。Click Deployment credentials.
  3. 输入用户名和密码。Enter a user name and password.
  4. 单击“保存”。Click Save.

设置部署凭据

完整的 FTP 用户名是“app\username”,其中 app 是 Web 应用的名称。The full FTP user name is “app\username” where app is the name of your web app. 用户名列在 Web 应用边栏选项卡的“软件包”下。The username is listed in the web app blade, under Essentials.

FTP 部署凭据

其他配置任务Other configuration tasks

SSLSSL

在“基本”或“标准”模式下,可为自定义域上传 SSL 证书。In Basic or Standard mode, you can upload SSL certificates for a custom domain. 有关详细信息,请参阅为 Web 应用启用 HTTPSFor more information, see Enable HTTPS for a web app.

若要查看上传的证书,请单击“所有设置” > “自定义域和 SSL”。To view your uploaded certificates, click All Settings > Custom domains and SSL.

域名Domain names

添加 Web 应用的自定义域名。Add custom domain names for your web app. 有关详细信息,请参阅为 Azure 应用服务中的 Web 应用配置自定义域名For more information, see Configure a custom domain name for a web app in Azure App Service.

若要查看域名,请单击“所有设置” > “自定义域和 SSL”。To view your domain names, click All Settings > Custom domains and SSL.

部署Deployments

若要查看部署槽,请单击“所有设置” > “部署槽”。To view your deployment slots, click All Settings > Deployment slots.

监视Monitoring

在“基本”或“标准”模式下,可以测试 HTTP 或 HTTPS 终结点的可用性,最多可测试三个地理分散的位置。In Basic or Standard mode, you can test the availability of HTTP or HTTPS endpoints, from up to three geo-distributed locations. 如果 HTTP 响应码为错误(4xx 或 5xx),或者响应时间超过 30 秒,则表示监视测试失败。A monitoring test fails if the HTTP response code is an error (4xx or 5xx) or the response takes more than 30 seconds. 如果从所有指定的位置监视测试均成功,则终结点被视为可用。An endpoint is considered available if the monitoring tests succeed from all the specified locations.

有关详细信息,请参阅如何监视 Web 终结点状态For more information, see [How to: Monitor web endpoint status].

备注

如果想要在注册 Azure 帐户之前开始使用 Azure 应用服务,请转到试用应用服务,可以通过该页面在应用服务中立即创建一个生存期较短的入门 Web 应用。If you want to get started with Azure App Service before signing up for an Azure account, go to [Try App Service], where you can immediately create a short-lived starter web app in App Service. 不需要使用信用卡,也不需要做出承诺。No credit cards required; no commitments.

后续步骤Next steps