ruby-on-rails - 无法分配请求的地址 - “xyz.herokuapp.com”端口 28159 的绑定 (2) (Errno::EADDRNOTAVAIL)
问题描述
我正在 Heroku 上上传 ROR 应用程序,但出现此错误。
/app/vendor/bundle/ruby/2.4.0/gems/puma-3.12.1/lib/puma/binder.rb:273:in 'initialize':
Cannot assign requested address - bind(2) for "xyz.herokuapp.com" port 28159 (Errno::EADDRNOTAVAIL)
我附上了 procfile 和 puma.rb 代码。
Procfile
:
web: bundle exec puma -c config/puma.rb
release: bundle exec rake db:migrate
puma.rb
:
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
我也试过 puma 3.7 但没有运气 procfile 的配置也改变了
在本地它工作正常,但在 heroku 给出错误。
解决方案
在 Heroku 上部署 Rails 6.0 时,我遇到了同样的问题。我使用了一个名为 HOST 的环境变量,以便向ActionDispatch::HostAuthorization中间件提供 heroku 服务器的 url,因为 rails 要求它以防止 DNS 重新绑定和其他主机头攻击。当 heroku 服务器尝试启动服务器时,环境变量 HOST 的名称会导致副作用,这里讨论了这个问题,我使用了与这里相同的解决方案。
- heroku 配置:取消设置主机
- heroku 配置:设置 DOMAIN=youdomain.com
- 在 production.rb 内部而不是
config.hosts << ENV['HOST']
使用config.hosts << ENV['DOMAIN']
- 在 git 上添加文件,在 heroku 上提交和部署
希望这会有所帮助。
推荐阅读
- python - 在 Google App Engine 中使用 Python 的私有存储库
- java - 批处理管道上的不同操作
- opengl-es - 使用“平面”着色器接口变量会导致性能大幅下降
- sql - Postgres 类似的查询需要不同的时间,不知道出了什么问题
- django - Django decimal SyntaxError:views.py 文件中的无效语法错误
- c++ - 在 C++ 中的“new”运算符之后使用“realloc”是否安全?
- android - GPIO 值总是在变化
- checkbox - 带有复选框和“a”元素的 ion-item - 单击“a”元素单击整个项目和复选框
- sql - 在 SQL 中选择不在当前表中的数字组合
- javascript - Webcodecamjs-QR 码扫描库在 Safari 浏览器中不起作用