python - 如何在 cPanel 上部署 FastAPI 应用程序?
问题描述
我正在尝试在 cPanel 上部署 FastAPI 应用程序,但我对启动 Unicorn 毫无头绪。下面是我的main.py文件代码。
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
async def root():
return {"message": "Hello World"}
@app.get('/items')
async def get_items():
return {"apples": 3, "oranges": 5}
这是我的passenger_wsgi.py文件代码:
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'main.py')
application = wsgi.app
解决方案
目前,Passenger 仅支持 WSGI。FastAPI 使用 ASGI,因此目前无法将其部署在Passenger 上。在乘客上支持 ASGI 应用程序存在一个未解决的问题。
推荐阅读
- html - 链接到外部 url 的角度重定向到应用程序
- javascript - 在 Chrome 中查找并复制 onclick 行为?
- python - 如何通过代理自动连接到 Cloud SQL?
- angular - 引导工具提示标题属性不适用于 Angular 6
- xcode - 带有“brew test-bot”的 Travis 任务失败了过时的命令行工具
- google-apps-script - Google Execution API 找不到共享函数
- javascript - JavaScript 函数仅适用于 index.html
- java - 让精灵在碰撞中消失?
- python - Scikit-learn TransformerMixin:“numpy.ndarray”对象没有属性“fit”
- php - Laravel:当验证失败时,可能有 {{ old('file') }} 值吗?如果是这样,怎么做?