【问题标题】:Steps or steps missing when manually starting Rails server手动启动 Rails 服务器时缺少步骤或步骤
【发布时间】:2019-09-10 19:24:36
【问题描述】:

我的 Rails 应用程序在我的本地开发环境 (Mac) 中运行良好。我将代码推送到测试服务器,并尝试手动启动它,但出现错误。详情如下:

OS: Ubuntu 18.04
Rails 5.2.3
Ruby 2.6.3
Puma
Webpacker
Nginx

我的 /etc/nginx/sites-enabled/myfqdn.com.conf 文件:

upstream puma {
  server unix:///home/test/shared/tmp/sockets/test-puma.sock;
}

server {
  listen 80 default_server deferred;
  server_name test.xxxxxx.com;

  root /home/amptest/public;
  access_log /home/test/log/nginx.access.log;
  error_log /home/test/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

我创建了目录:

/home/myapp/shared
/home/myapp/shared/tmp
/home/myapp/shared/tmp/sockets
/home/myapp/shared/tmp/pids

我的 config/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" }
plugin :tmp_restart

在我的 .bashrc 中,我有:

export RAILS_ENV='test'

在我的 Gemfile 中,我有:

gem 'puma'
gem 'webpacker'

我跑了:

bundle install

没有错误

并成功进行了数据库迁移:

rake db:migrate

并为 DB 播种:

rake db:seed

然后我做了:

bundle exec rake assets:precompile

正确完成的:

bundle exec rake assets:precompile
2019-09-10 01:36:10 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
yarn install v1.17.3
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.76s.
I, [2019-09-10T01:36:13.413669 #3461]  INFO -- : Writing /home/myapp/public/assets/express/lib/application-9232ebdb20ad39572e70fb9e29810e63dbb63b58f5f18617c7c2bc8bd28321b5.js
I, [2019-09-10T01:36:13.413941 #3461]  INFO -- : Writing /home/myapp/public/assets/express/lib/application-9232ebdb20ad39572e70fb9e29810e63dbb63b58f5f18617c7c2bc8bd28321b5.js.gz
Compiling…
Compiled all packs in /home/test/public/packs-test

但我尝试访问 test.xxxxxx.com,我收到错误“出错了”。

nginx 错误日志说:

2019/09/10 05:38:21 [crit] 1192#1192: *1 connect() to unix:///home/test/shared/tmp/sockets/test-puma.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xxx.xxxx, server: test.xxxxxx.com, request: "GET / HTTP/1.1", upstream: "http://unix:///home/test/shared/tmp/sockets/test-puma.sock:/", host: "test.xxxxxx.com"
2019/09/10 05:38:47 [info] 1192#1192: *3 client closed connection while waiting for request, client: xx.xxx.xxx.xxxx, server: 0.0.0.0:80

所以,我错过了一个或更多步骤,包括我需要做些什么来确保 Puma 正确启动。有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails nginx puma


    【解决方案1】:

    这是因为应用的 rails 服务器没有运行。你从来没有运行过rails server 命令。

    如果您将其用于测试/开发目的,请考虑:

    • 在端口 3001,rails s -b 0.0.0.0 -p 3001 启动 rails 服务器
    • 然后在 nginx 配置中使用 rails server URL 来反向代理请求:

      proxy_pass http://127.0.0.1:3001
      

    如果您将其用于生产,请考虑使用Passenger,您可以看到乘客安装docs here

    【讨论】:

    • 这不在我的本地系统上。它位于 AWS 上的远程服务器上。该应用程序指定 puma 不是乘客
    • 你确定你的rails server cmd 没有抛出任何错误吗?
    • 我切换到乘客,当我启动服务器时,我没有收到任何错误。我仍然收到 404 not found 错误
    • 这是测试服务器,所以RAILS_ENV=test
    猜你喜欢
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2018-11-27
    相关资源
    最近更新 更多