我正在处理在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.
其中66.226.247.55 -外部IP从谷歌云平台的实例,我如何启动一个项目,使它可以通过IP访问?
发布于 2022-05-18 12:05:35
如果您使用的是nginx服务器
在/etc/nginx/site中创建一个文件,启用/创建文件,将fastapi_nginx代码复制到文件中并进行相应调整
server{
listen 80;
server_name "your public ip";
location / {
proxy_pass http://127.0.0.1:8000; #localhost
}
}
这将重新路由到您的公共ip。
发布于 2020-07-14 15:59:18
您不能在本地GCP中的远程服务器上启动快速api应用程序。
您必须将应用程序部署到GCP。换句话说,您需要在远程服务器而不是本地主机上运行该命令。
https://stackoverflow.com/questions/62898917
复制相似问题