使用nginx的乘客:无法加载此类文件 - bundler / setup(LoadError)

时间:2014-09-29 08:38:39

标签: ruby-on-rails nginx passenger

只安装了一个版本的Ruby,我运行了gem install bundler && bundle install

nginx conf

passenger_root /root/.gem/ruby/2.1.0/gems/passenger-4.0.52;
passenger_ruby /usr/bin/ruby;
server {
    listen 80;
    server_name example.com;
    root /srv/http/myrailsapp/public;
    passenger_enabled on;
    rails_env development;
}

错误日志

cannot load such file -- bundler/setup (LoadError)
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/lib/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/lib/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/lib/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/helper-scripts/rack-preloader.rb:100:in `preload_app'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/helper-scripts/rack-preloader.rb:158:in `<module:App>'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/root/.gem/ruby/2.1.0/gems/passenger-4.0.52/helper-scripts/rack-preloader.rb:28:in `<main>'

4 个答案:

答案 0 :(得分:10)

我一直在解决类似的问题。

我的问题是配置passenger_ruby /usr/bin/ruby;哪个指向不正确的版本。我的解决方案是设置命令which ruby

的输出路径

在服务器上我使用rvm。但是还有其他红宝石的存在。

首先尝试测试环境。转到应用程序目录并运行passenger start。如果服务器已准备好运行应用程序,这将向您显示。修复错误......

如果消息仍然显示

cannot load such file -- bundler/setup (LoadError)

运行gem install bundler并重新检查。

然后将NGINX中的路径设置为which ruby命令的路径并重新启动应用程序。

答案 1 :(得分:1)

您需要更改passenger_root值。像here in doc

一样

例如我的nginx配置:

...
  passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
  passenger_ruby /usr/bin/ruby;
...

答案 2 :(得分:0)

一小时前有一个类似的问题。在这里查看我的答案:https://stackoverflow.com/a/26095080/20816

答案 3 :(得分:0)

乘机乘客无法找到红宝石路径,查看红宝石路径是否正确,或者是否由于服务器更新或其他原因删除了符号链接。

CentOS 7 Ruby 2.6.3 Rbenv

const winston = require('winston');
const {Loggly} = require('winston-loggly-bulk');
const tag = (process.env['HOSTNAME']) ? (process.env['HOSTNAME']) : 'localhost';
const {splat, combine, printf, colorize, timestamp, simple} = winston.format;
let alignColorsAndTime = combine(
    colorize({
        all:true
    }),
    timestamp({
        format:"YYYY-MM-DD HH:MM:SS"
    }),
    printf(msg => {
        if (msg.errno !== undefined) {
            msg.message = JSON.stringify(msg)
        }
        return msg.level + msg.timestamp + msg.message;
    })
);

//Logging levels: error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5
winston.add(new Loggly({
    token: [REMOVED],
    subdomain: [REMOVED],
    tags: [[REMOVED] + process.env['ENVIRONMENT'], tag],
    json: true,
    level : (process.env['LOG_LEVEL']) ? (process.env['LOG_LEVEL']) : 'debug'
}));
winston.add(new winston.transports.Console({
    format: alignColorsAndTime,
    level : 'debug',
}));


module.exports = winston;