You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Digital Ocean部署FastAPI报错:未指定应用模块

在DigitalOcean部署FastAPI时解决"Error: No application module specified"问题

项目环境与配置

项目文件夹结构:

app.py
gunicorn.config.py
Procfile
requirements.txt

gunicorn.config.py内容:

bind = "0.0.0.0:8080"
workers = 2
worker_class = "uvicorn.workers.UvicornWorker"

Procfile内容:

gunicorn --worker-tmp-dir /dev/shm --config gunicorn.config.py app:app

requirements.txt内容:

fastapi
selenium
uvicorn
gunicorn

构建阶段已成功,但部署日志出现错误:Error: No application module specified.

解决办法

1. 修正Procfile的进程类型前缀

DigitalOcean App Platform要求Procfile中的命令必须以进程类型标识开头(比如web:),否则无法正确识别应用入口。将Procfile内容修改为:

web: gunicorn --worker-tmp-dir /dev/shm --config gunicorn.config.py app:app

2. 确认app.py中的应用实例名称

检查app.py中FastAPI实例的命名,确保实例名为app:

from fastapi import FastAPI

app = FastAPI()  # 这里的实例名必须和Procfile中的app:app对应

# 后续路由代码...

如果实例名不是app(比如叫api),需要同步修改Procfile中的入口为app:api。

3. 验证工作目录与文件路径

确保部署时的工作目录为项目根目录,gunicorn能找到app.py和gunicorn.config.py。可以在Procfile中明确指定相对路径:

web: gunicorn --worker-tmp-dir /dev/shm --config ./gunicorn.config.py ./app:app

内容的提问来源于stack exchange,提问作者Junaid Nazir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 21:28:20