首页 > 解决方案 > 无法分配请求的地址 - “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 给出错误。

标签: ruby-on-railsherokurubygemspumaheroku-cli

解决方案


在 Heroku 上部署 Rails 6.0 时,我遇到了同样的问题。我使用了一个名为 HOST 的环境变量,以便向ActionDispatch::HostAuthorization中间件提供 heroku 服务器的 url,因为 rails 要求它以防止 DNS 重新绑定和其他主机头攻击。当 heroku 服务器尝试启动服务器时,环境变量 HOST 的名称会导致副作用,这里讨论了这个问题,我使用了与这里相同的解决方案。

  1. heroku 配置:取消设置主机
  2. heroku 配置:设置 DOMAIN=youdomain.com
  3. 在 production.rb 内部而不是config.hosts << ENV['HOST']使用config.hosts << ENV['DOMAIN']
  4. 在 git 上添加文件,在 heroku 上提交和部署

希望这会有所帮助。


推荐阅读