python - 如何使用 gunicorn 将 heroku nginx buildpack 添加到 python django 应用程序?
问题描述
我正在尝试在heroku上部署一个带有django的python,并将一个nginx反向代理配置为像一个过滤器一样,在将令牌检查给第三方IDP之前,它不会让请求传递到我的django后端。
** 第 1 步 **
我正在按照本教程添加 nginx buildpack:https ://elements.heroku.com/buildpacks/hq-mobile/v3-nginx-buildpack
添加 buildpack 并启动应用程序后,我收到以下消息:bin/start-nginx: line 37: bundle: command not found
经过一番挖掘后,我注意到需要将一些路径添加到 heroku 应用程序的配置变量中,以便捆绑程序获得所需的依赖项:
所以我添加了这个路径:
heroku config:add GEM_PATH=vendor/bundle/1.9.3
heroku config:set PATH=bin:vendor/bundle/ruby/1.9.3/bin:/usr/local/bin:/usr/bin:/bin
然后是config/unicorn.rb文件:
require 'fileutils'
listen '/tmp/nginx.socket'
before_fork do |server,worker|
FileUtils.touch('/tmp/app-initialized')
end
档案:
web: bin/start-nginx bundle exec unicorn -c config/unicorn.rb gunicorn -c gunicorn.conf.py MyApp.wsgi
gunicorn.conf.py
# gunicorn.conf
def when_ready(server):
# touch app-initialized when ready
open('/tmp/app-initialized', 'w').close()
bind = 'unix:///tmp/nginx.socket'
workers = 4
即使添加了这个,错误仍然存在。
** 第 2 步 **
一旦正常的 buildpack 就位,我想按照本教程来配置我想要的 nginx:
https://www.nginx.com/blog/validating-oauth-2-0-access-tokens-nginx/
需要什么配置才能让这个 buildpack 在我的情况下工作?
解决方案
bundle exec
要解决此问题,请从 Procfile中删除该部分。换句话说,您的 Procfile 变为:
web: bin/start-nginx unicorn -c config/unicorn.rb gunicorn -c gunicorn.conf.py MyApp.wsgi
(旁注:仅使用可能会出现错误,MyApp.wsgi
因为您可能需要将其更改为诸如MyApp.wsgi:application
公开应用程序的环境变量之类的东西)
推荐阅读
- django - SESSION_EXPIRE_AT_BROWSER_CLOSE 不工作
- django - 在 django 中获取不通过数据库的子模型
- unix - 粘贴 - 空列
- flutter - 调试颤振控制台充满随机错误消息
- javascript - VSCode:设置中的 TypeScript 扩展
- javascript - 无法连接到 localhost 端口 8000:Node.js 中的连接被拒绝
- javascript - AJAX 附加结果重复
- python - 如何在 Python 中使用正则表达式提取格式化字符串?
- css - 如何使用斜线分隔符创建两种颜色的内容?
- node.js - 在 Node js 中,如果新请求到达并且事件循环已经忙于处理请求会发生什么?