7

我正在处理将 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 访问?

4

2 回答 2

15

--host应该是 GCP 服务器的本地地址。

uvicorn main:app --host 0.0.0.0 --port 8000

现在通过http://66.226.247.55:8000

注意:您应该打开GCP 服务器的8000 端口

于 2020-07-14T17:31:38.950 回答
-2

您无法在本地启动您的快速 api 应用程序到 GCP 中的远程服务器。

您必须将应用部署到 GCP。换句话说,您需要在远程服务器而不是本地主机上运行该命令。

于 2020-07-14T15:59:18.297 回答