azure - 如何在 Azure 应用服务上部署 FastAPI

标签 azure deployment azure-web-app-service fastapi uvicorn

我想将一个简单的 FastAPI 部署到 Azure 应用服务上,但我不断收到此错误消息。

enter image description here

这是我的 API。

from fastapi import FastAPI

app = FastAPI()

@app.get('/')
async def welcome():
    return {'message':'Wecome to My website!'}

该 API 在我的本地计算机上运行良好。我在 VS code 终端上使用的命令是“uvicorn main: app”。

为了部署我的应用程序,我有startup.sh,其中只有一个命令行:

gunicorn -w 2 -k uvicorn.workers.UvicornWorker main:app

我已经设置了应用服务的配置:

enter image description here

定价等级为:

enter image description here

我在管道中没有看到任何问题:

enter image description here

或者,我尝试了startup.sh中的以下每一行代码:

python -m uvicorn main:app
gunicorn --bind=0.0.0.0 --timeout:600 main:app

但是都失败了。非常感谢您的帮助!

最佳答案

There are three main ways to deploy this to Azure:

  • Deploy with the VS Code Azure Functions extension.
  • Deploy with the Azure CLI.
  • Deploy with the Azure Developer CLI: After installing the azd tool, run azd up in the root of the project. You can also run azd pipeline config to set up a CI/CD pipeline for deployment.

更多信息请点击:Using FastAPI Framework with Azure Functions

关于azure - 如何在 Azure 应用服务上部署 FastAPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74343574/

相关文章:

azure - 为什么 `Arr-Disable-Session-Affinity` header 会出现在我的 Azure Web 应用程序(网站)上?

Azure Keyvault错误: Tried the following 3 methods to get an access token,但它们都不起作用

c# - 将数据添加到缓存时出现重复的键

javascript - `npm install`是否支持并发运行?

java - 部署 WAR 文件会在 Tomcat 上给我一个 404 状态码?

c# - 覆盖客户端证书身份验证验证

azure - 如何知道 Azure 网站实例(WebApp)关闭的原因?

azure - TrackRequest() 数据显示在门户中的什么位置?

visual-studio - 我的 CSS 图像无法在 Windows Azure 上运行

android - 适用于企业环境的 native 移动应用程序部署