首页 > 解决方案 > 如何在 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

标签: pythonpython-3.xapicpanelfastapi

解决方案


目前,Passenger 仅支持 WSGI。FastAPI 使用 ASGI,因此目前无法将其部署在Passenger 上。在乘客上支持 ASGI 应用程序存在一个未解决的问题。


推荐阅读