部署 Ubuntu 14.04 上使用 Nginx + Passenger 部署 Ruby on Rails 错误, cannot load such file -- bundler/setup

Marco2016 · 2016年10月23日 · 最后由 Marco2016 回复于 2016年10月23日 · 3589 次阅读

在本地和 Heroku 上均可以运行
但是想练习使用 Nginx, Passenger, Capistrano 进行部署时却出现错误

/etc/nginx/sites-enabled/default 这里就用的 gorails 给的写法

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        server_name 域名;
        passenger_enabled on;
        rails_env    production;
        root         /home/deploy/myapp/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

/var/log/nginx/error.log

[ 2016-10-23 03:40:38.1167 24173/7fbabb218700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /home/deploy/myapp/current: An error occurred while starting up the preloader.
  Error ID: de709b70
  Error details saved to: /tmp/passenger-error-U7XDgA.html
  Message from application: cannot load such file -- bundler/setup (LoadError)
  /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'


[ 2016-10-23 03:40:38.1291 24173/7fbabc21a700 age/Cor/Con/CheckoutSession.cpp:285 ]: [Client 1-3] Cannot checkout session because a spawning error occurred. The identifier of the error is de709b70. Please see earlier logs for details about the error.

参考了论坛里如下几篇类似问题的解决方法,仍然没有悟道适合的办法
https://ruby-china.org/topics/30114
https://ruby-china.org/topics/22368
https://github.com/peatio/peatio/issues/225

麻烦诸位指点下

=====================================================================================
新错误提示:
在服务器上用 sudo service nginx restart 显示 ok 的,但是网页完全打不开了,显示 ERR_CONNECTION_REFUSED

04:37 passenger:restart
      01 passenger-config restart-app /home/deploy/myapp --ignore-app-not-running

passenger-config stderr: *** ERROR: Phusion Passenger doesn't seem to be running. If you are sure that it
is running, then the causes of this problem could be one of:

 1. You customized the instance registry directory using Apache's
    PassengerInstanceRegistryDir option, Nginx's
    passenger_instance_registry_dir option, or Phusion Passenger Standalone's
    --instance-registry-dir command line argument. If so, please set the
    environment variable PASSENGER_INSTANCE_REGISTRY_DIR to that directory
    and run this command again.
 2. The instance directory has been removed by an operating system background
    service. Please set a different instance registry directory using Apache's
    PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir
    option, or Phusion Passenger Standalone's --instance-registry-dir command
    line argument.


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


 DEBUG [469b6021]       PassengerInstanceRegistryDir option, Nginx's

 DEBUG [469b6021]   

 DEBUG [469b6021]       passenger_instance_registry_dir option, or Phusion Passenger Standalone's

 DEBUG [469b6021]   

 DEBUG [469b6021]       --instance-registry-dir command line argument. If so, please set the

 DEBUG [469b6021]   

 DEBUG [469b6021]       environment variable PASSENGER_INSTANCE_REGISTRY_DIR to that directory

 DEBUG [469b6021]   

 DEBUG [469b6021]       and run this command again.

 DEBUG [469b6021]   

 DEBUG [469b6021]    2. The instance directory has been removed by an operating system background

 DEBUG [469b6021]   

 DEBUG [469b6021]       service. Please set a different instance registry directory using Apache's

 DEBUG [469b6021]   

 DEBUG [469b6021]       PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir

 DEBUG [469b6021]   

 DEBUG [469b6021]       option, or Phusion Passenger Standalone's --instance-registry-dir command

 DEBUG [469b6021]   

 DEBUG [469b6021]       line argument.

 DEBUG [469b6021]

似乎 nginx 没有配置 ruby 的路径,passenger 找到的系统 ruby 也许不是你要的那个。

https://gorails.com/deploy/ubuntu/16.04

搜 passenger_ruby 这一段

@Rei 谢谢,教程又重新安装了两次,现在网页都打不开了,ERR_CONNECTION_REFUSED
当我用 sudo /usr/bin/passenger-config validate-install 来测 passenger 的时候显示安装时没问题的
更新的错误提示复制到了帖子上,麻烦了

没遇到过这错误,删掉环境跟着 gorails 教程一步一步做一遍吧。

@Rei 谢谢,再试几次

需要 登录 后方可回复, 如果你还没有账号请 注册新账号