发布到 Azure 应用服务Publish to Azure App Service

目前,仅适用于 Linux 的 Azure 应用服务支持 Python,可按照本文所述使用 Git deploy容器发布应用。At present, Python is supported on Azure App Service for Linux, and you can publish apps using Git deploy and containers, as described in this article.

备注

适用于 Windows 的 Azure 应用服务对的 Python 支持已遭正式弃用。Python support on Azure App Service for Windows is officially deprecated. 因此,仅 IIS 目标正式支持 Visual Studio 中的“发布”命令,Azure 应用服务中的远程调试功能已不再正式受支持。As a result, the Publish command in Visual Studio is officially supported only for an IIS target, and remote debugging on Azure App Service is no longer officially supported.

不过,发布到 Windows 上的应用服务功能目前仍有效,因为 Windows 上的应用服务适用的 Python 扩展仍可用,但我们不再会为它提供服务或更新它。However, Publishing to App Service on Windows features still works for the time being, as the Python extensions for App Service on Windows remain available but will not be serviced or updated.

使用 Git 部署流程发布到 Linux 上的应用服务Publish to App Service on Linux using Git deploy

Git 部署流程可将 Linux 上的应用服务连接到 Git 存储库的特定分支。Git deploy connects an App Service on Linux to a specific branch of a Git repository. 向相应分支提交的代码会自动部署到应用服务,并且应用服务会自动安装 requirements.txt 中列出的任何依赖项。Committing code to that branch automatically deploys to the App Service, and App Service automatically installs any dependencies listed in requirements.txt. 在此示例中,Linux 上的应用服务在使用 Gunicorn Web 服务器的预配置容器映像中运行代码。In this case, App Service on Linux runs your code in a pre-configured container image that uses the Gunicorn web server. 目前,此服务处于预览阶段,不支持用于生产。At present, this service is in Preview and not supported for production use.

有关详细信息,请参阅 Azure 文档中的以下文章:For more information, see the following articles in the Azure documentation:

使用容器发布到 Linux 上的应用服务Publish to App Service on Linux using containers

可提供你自己的容器,而不用依赖 Linux 上的应用服务随附的预生成容器。Instead of relying on the pre-built container with App Service on Linux, you can provide your own container. 借助此选项,可选择要使用的 Web 服务器,并能自定义容器行为。This option allows you to choose which web servers you use and to customize the container's behavior.

生成、管理和推送容器的方法有以下两种:There are two options to build, manage, and push containers:

  • 使用 Visual Studio Code 和 Docker 扩展,如使用 Docker 容器部署 Python 应用中所述。Use Visual Studio Code and the Docker extension, as described on Deploy Python using Docker Containers. 即使不使用 Visual Studio Code,这篇文章还详细介绍了如何使用生产就绪的 uwsgi 和 nginx Web 服务器,以生成 Flask 和 Django 应用的容器映像。Even if you don't use Visual Studio Code, the article provides helpful details on building container images for Flask and Django apps using the production-ready uwsgi and nginx web servers. 然后便可以使用 Azure CLI 部署这些相同的容器。You can then deploy those same container using the Azure CLI.

  • 使用命令行和 Azure CLI,如 Azure 文档中的使用自定义 Docker 映像一文所述。Use the command line and Azure CLI, as described on Use a custom Docker image in the Azure documentation. 不过,此为通用指南,不是 Python 专用指南。This guide is generic, however, and not specific to Python.

发布到 IISPublish to IIS

在 Visual Studio 中,可以将应用发布到 Windows 虚拟机,或其他运行 IIS 且包含“发布” 命令的计算机。From Visual Studio, you can publish to a Windows virtual machine or other IIS-capable computer with the Publish command. 使用 IIS 时,请务必在应用中创建或修改 web.config 文件,以指示 IIS 在哪里能找到 Python 解释器。When using IIS, be sure to create or modify a web.config file in the app that tells IIS where the find the Python interpreter. 有关详细信息,请参阅为 Web 应用配置 IISFor more information, see Configure web apps for IIS.