gunicorn - 在 ubuntu 服务器上使用 uvicorn 运行 fastapi 应用程序
问题描述
我正在处理将 FastAPI 上的项目沉积到远程 ubuntu 服务器。我将尝试通过命令从终端(使用 SSH 连接)运行项目
gunicorn -k uvicorn.workers.UvicornWorker main:app
输出是
gunicorn -k uvicorn.workers.UvicornWorker main:app
[2020-07-14 15:24:28 +0000] [23102] [INFO] Starting gunicorn 20.0.4
[2020-07-14 15:24:28 +0000] [23102] [INFO] Listening at: http://127.0.0.1:8000 (23102)
[2020-07-14 15:24:28 +0000] [23102] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-07-14 15:24:28 +0000] [23104] [INFO] Booting worker with pid: 23104
[2020-07-14 15:24:28 +0000] [23104] [INFO] Started server process [23104]
[2020-07-14 15:24:28 +0000] [23104] [INFO] Waiting for application startup.
[2020-07-14 15:24:28 +0000] [23104] [INFO] Application startup complete.
但我需要该项目在服务器的 IP 地址上可用。如果我尝试
uvicorn main:app --host 66.226.247.55 --port 8000
我明白了
INFO: Started server process [23308]
INFO: Waiting for application startup.
INFO: Connected to database postgresql://recognition:********@localhost:5432/reco
INFO: Application startup complete.
ERROR: [Errno 99] error while attempting to bind on address ('66.226.247.55', 8000): cannot assign requested address
INFO: Waiting for application shutdown.
INFO: Disconnected from database postgresql://recognition:********@localhost:5432/reco
INFO: Application shutdown complete.
Where 66.226.247.55 - 来自谷歌云平台实例的外部 IP 地址 如何启动项目以便可以通过 IP 访问?
解决方案
--host
应该是 GCP 服务器的本地地址。
uvicorn main:app --host 0.0.0.0 --port 8000
现在通过http://66.226.247.55:8000
注意:您应该打开GCP 服务器的8000 端口。
推荐阅读
- sql-server - 如何存储将要本地化的静态数据?
- php - 产品 setMetaTitle 在 Magento 2.2 PHP 中不起作用
- angular - 测试在组件 Angular5 中调用 http 服务的函数
- android - 我想以编程方式更新 Firebase 远程配置中的参数
- r - 更改 data.table 中 POSIXct 的年份
- tfs - Compartilhar Shelve com outros Membros TFS
- java - 如何使用安卓手机的壁纸作为空活动的背景?
- javascript - 有条件地设置“数据远程” - Javascript
- android - Firebase Auth和Facebook登录android - 检查用户是否是新用户?
- c# - 如何检查 HttpWebResponse 是否给出状态码 200?