python - Heroku Procfile.windows 行为异常
问题描述
我正在尝试将我的 Django 应用程序部署到 Heroku。我在 Windows 上工作,但是当我命名我的 procfile 时,Procfile.windows
我得到一个
Procfile declares types -> (none)
错误。当我命名它时,Procfile
我得到一个
bash: py: command not found
这是文件:
web: py manage.py runserver 0.0.0.0:8000
我尝试使用python
而不是py
得到
Build succeeded
2020-09-01T06:48:12.435733+00:00 app[web.1]: Watching for file changes with StatReloader
2020-09-01T06:48:12.436952+00:00 app[web.1]: Performing system checks...
2020-09-01T06:48:12.436953+00:00 app[web.1]:
2020-09-01T06:48:12.883911+00:00 app[web.1]: System check identified no issues (0 silenced).
2020-09-01T06:48:13.163963+00:00 app[web.1]: September 01, 2020 - 06:48:13
2020-09-01T06:48:13.164126+00:00 app[web.1]: Django version 3.1, using settings 'lunaSite.settings'
2020-09-01T06:48:13.164127+00:00 app[web.1]: Starting development server at http://0.0.0.0:8000/
2020-09-01T06:48:13.164128+00:00 app[web.1]: Quit the server with CONTROL-C.
2020-09-01T06:48:13.000000+00:00 app[api]: Build succeeded
2020-09-01T06:48:13.767832+00:00 app[web.1]: Watching for file changes with StatReloader
2020-09-01T06:48:13.768157+00:00 app[web.1]: Performing system checks...
2020-09-01T06:48:13.768163+00:00 app[web.1]:
2020-09-01T06:48:14.101794+00:00 app[web.1]: System check identified no issues (0 silenced).
2020-09-01T06:48:14.264505+00:00 app[web.1]: September 01, 2020 - 06:48:14
2020-09-01T06:48:14.264609+00:00 app[web.1]: Django version 3.1, using settings 'lunaSite.settings'
2020-09-01T06:48:14.264609+00:00 app[web.1]: Starting development server at http://0.0.0.0:8000/
2020-09-01T06:48:14.264610+00:00 app[web.1]: Quit the server with CONTROL-C.
2020-09-01T06:49:08.160313+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-09-01T06:49:08.188765+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-09-01T06:49:08.320546+00:00 heroku[web.1]: Process exited with status 137
2020-09-01T06:49:10.304145+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-09-01T06:49:10.328270+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-09-01T06:49:10.419954+00:00 heroku[web.1]: Process exited with status 137
2020-09-01T06:49:10.489203+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-01T06:49:12.722670+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=lunawebsite.herokuapp.com request_id=04a84a44-53b8-409d-b2ef-4403c8aabb67 fwd="73.69.214.229" dyno= connect= service= status=503 bytes= protocol=https
2020-09-01T06:49:13.347117+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=lunawebsite.herokuapp.com request_id=8c3c75d6-e6b7-48c6-8cc5-1540c1133ea7 fwd="73.69.214.229" dyno= connect= service= status=503 bytes= protocol=https
2020-09-01T06:49:13.628310+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=lunawebsite.herokuapp.com request_id=c67d8f0e-c8c8-4212-a042-db9e3d58c64e fwd="73.69.214.229" dyno= connect= service= status=503 bytes= protocol=https
2020-09-01T06:49:22.655764+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=lunawebsite.herokuapp.com request_id=c4046069-581e-4315-8b4d-4212298559fd fwd="73.69.214.229" dyno= connect= service= status=503 bytes= protocol=https
2020-09-01T06:49:22.778778+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=lunawebsite.herokuapp.com request_id=3c15c236-1945-4c3e-a047-9806f8ce6255 fwd="73.69.214.229" dyno= connect= service= status=503 bytes= protocol=https
这里有什么问题,我该如何解决?
解决方案
bash: py: command not found
没错,py
不会被发现。py.exe
仅存在于 Windows 上,Heroku 不运行 Windows。并且文件应该被调用Procfile
,而不是Procfile.windows
.
改用python
:
web: python manage.py runserver 0.0.0.0:8000
您可能还想考虑使用django-heroku
,它有助于在 Django 项目中设置一堆 Heroku 特定的东西。
既然已经解决了,这里还有一些其他问题:
你不能在 Heroku 上选择你的端口。一个将通过
PORT
环境变量动态分配给您。这是您上面提到的启动超时错误的原因。-
请勿在生产环境中使用此服务器。它没有经过安全审计或性能测试。(这就是它要保持的方式。我们的业务是制作 Web 框架,而不是 Web 服务器,因此改进此服务器以使其能够处理生产环境超出了 Django 的范围。)
你需要一个合适的网络服务器。Gunicorn 是一个常见的选择,但它不适用于 Windows。如果您仍然想使用它,请添加gunicorn
到您的依赖项并在您的 中使用类似的内容Procfile
,替换<project_name>
为您的项目名称:
web: gunicorn <project_name>.wsgi -b 0.0.0.0:$PORT
但是,这在本地不起作用。如果您想要在 Windows 和 Heroku 上运行的东西,请查看 Waitress 和 uWSGI。
推荐阅读
- javascript - “srcWnd 未定义” - TamperMonkey
- c# - 以数字为键反序列化 JSON
- flutter - Flutter Firestore 返回 Future
- > 返回空
- symfony - Symfony + WSSE:为什么 nonce 缓存文件夹大小为 20GB?
- powershell - Powershell - 可变数量的驱动器
- java - spring boot 不创建所有表 - Spring Boot,MySQL,jpa
- java - 如何将 JsonObject 对象转换为另一种对象类型的列表
- palantir-foundry - 当我进行编辑时,写回数据集会自动更新吗?
- php - 带小数分隔符的 PHP 返回价格
- python - 绘制数据框热图中的所有列