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

Heroku部署Django应用时Procfile文件应该如何正确配置?

Heroku部署Django的Procfile正确配置及报错解决

Procfile基础格式要求

  • 文件名必须为Procfile:首字母大写,无任何后缀,存储在项目根目录,和manage.py文件同级
  • 内容语法强制要求为进程类型: 启动命令,冒号后必须加空格,你之前看到的web gunicorn、web:gunicorn都是错误写法,只有web: gunicorn的格式是合法的

正确的Django启动配置

Django项目的Procfile内容按如下规则填写:

web: gunicorn 你的项目实际名称.wsgi --log-file -

参数说明:

  • 你的项目实际名称:对应你项目中包含wsgi.py的文件夹名称,比如你的项目结构是my_site/manage.py、my_site/my_site/wsgi.py,这里就填my_site,不要直接复制网上的示例appname
  • 末尾加--log-file -是为了将运行日志输出到Heroku日志面板,方便后续排查问题

常见报错原因及修复

1. 执行heroku ps:scale web=1提示Couldn't find that process type (web)

触发原因:

  • Procfile文件名错误(比如小写procfile、带.txt后缀)或存储路径不对
  • Procfile格式不符合要求,无法识别web进程
  • 修改完Procfile后未提交推送到Heroku就直接执行scale命令

2. 启动后报错at=error code=H14 desc="No web processes running"

触发原因:

  • gunicorn后填写的wsgi路径和实际项目结构不匹配
  • 你的requirements.txt文件中没有添加gunicorn依赖,Heroku无法找到启动命令
  • 修改完配置后未推送到Heroku,或推送后进程启动失败

完整操作流程

  1. 按上述要求修改Procfile内容
  2. 在requirements.txt中添加gunicorn依赖,示例:
gunicorn==20.1.0
  1. 提交修改并推送到Heroku:
git add Procfile requirements.txt
git commit -m "修复Procfile配置"
git push heroku main

如果你的项目主分支为master,将最后一行的main替换为master即可
4. 推送完成后执行进程扩容命令:

heroku ps:scale web=1

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 17:36:02