【发布时间】:2019-09-08 10:30:31
【问题描述】:
我一直在我的本地机器上进行一些 Ruby on Rails 开发,我想在我自己的 Web 服务器上托管一个 Rails 应用程序,这是我从头开始设置的。它运行 Ubuntu 18.04 并使用 nginx 作为服务器。我按照this site 上的说明在我的服务器上设置 Rails 并创建了一个测试应用程序。这是我的 config/database.yml 文件:
# PostgreSQL. Versions 9.1 and up are supported.
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
username: <my username>
password: <my password>
host: localhost
port: 5432
test:
<<: *default
database: myapp_test
host: localhost
port: 5432
username: <my username>
password: <my password>
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
但是,当我尝试运行 rails 服务器时,它会出现以下情况:
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
Exiting
Traceback (most recent call last):
29: from bin/rails:9:in `<main>'
28: from /home/username/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
27: from /home/username/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
26: from /home/username/.rvm/gems/ruby-2.6.3/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
25: from /home/username/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
24: from /home/username/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
23: from /home/username/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
22: from /home/username/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
21: from /home/username/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
20: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
19: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
18: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
17: from /home/username/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
16: from /home/username/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
15: from /home/username/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
14: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `perform'
13: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `tap'
12: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:147:in `block in perform'
11: from /home/username/.rvm/gems/ruby-2.6.3/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:53:in `start'
10: from /home/username/.rvm/gems/ruby-2.6.3/gems/rack-2.0.7/lib/rack/server.rb:297:in `start'
9: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/rack/handler/puma.rb:73:in `run'
8: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/launcher.rb:186:in `run'
7: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/single.rb:98:in `run'
6: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/runner.rb:153:in `load_and_bind'
5: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/binder.rb:90:in `parse'
4: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/binder.rb:90:in `each'
3: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/binder.rb:106:in `block in parse'
2: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/binder.rb:273:in `add_tcp_listener'
1: from /home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/binder.rb:273:in `new'
/home/username/.rvm/gems/ruby-2.6.3/gems/puma-3.12.1/lib/puma/binder.rb:273:in `initialize': Cannot assign requested address - bind(2) for "192.168.7.202" port 5432 (Errno::EADDRNOTAVAIL)
我用谷歌搜索了错误,但没有任何帮助。我的 IPv6 已打开(应该注释掉的行是)。我尝试了不同的本地 IP 地址和不同的端口号(3000、3001、5432、8080),但没有任何效果。
任何帮助将不胜感激。
【问题讨论】:
-
正如 Puma 输出所说,它在开发模式下运行,而不是在生产模式下运行,所以我猜你没有正确配置 puma 和 nginx。我会搜索 pump 和 nginx rails 服务器 - 并按照教程进行操作。
-
另请注意,在您链接的教程中,测试环境中的 db 端口 5432 存在拼写错误(请参阅教程末尾的 cmets)。
标签: ruby-on-rails ruby ruby-on-rails-5