ubuntu+nginx+gunicorn+uvicorn+fastapi应用的部署
Ubuntu系统下nginx的安装和配置请参考https://editor.youkuaiyun.com/md/?articleId=128820221
Gunicorn是一个使用WSGI标准的应用服务器。Flask和DJango可以直接使用Gunicorn运行,但是FastAPI不能直接使用Gunicorn,因为FastAPI使用最新的ASGI标准。
Gunicorn可以作为进程管理器使用,并且可以设定进程的类型,Uvicorn可以作为Gunicorn的进程类型。使用这种组合,Gunicorn将充当进程管理器,监听端口和IP。它会将接收到的数据传输到运行Uvicorn类的工作进程,然后,Uvicorn将数据传输给FastAPI。
启动命令
gunicorn main:app --workers 2 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
回显
[2023-02-01 11:27:35 +0800] [623487] [INFO] Starting gunicorn 20.1.0
[2023-02-01 11:27:35 +0800] [623487] [INFO] Listening at: http://0.0.0.0:8000 (623487)
[2023-02-01 11:27:35 +0800] [623