ruby - $ GEM_HOME和$ GEM_PATH在旅客中设置错误

标签 ruby nginx docker rubygems passenger

我正在尝试在docker容器中使用Passenger(v5.1.4)+ Nginx设置rails(v4.2.6)应用程序。
我使用官方 ruby 2.3.1作为基本图像。

以下是我的网站nginx文件

server {
  server_name example.local;

  listen 4000;

  access_log /var/log/nginx/access.log;
  error_log  /var/log/nginx/error.log;

  root /www/app/public;

  passenger_ruby /usr/local/bin/ruby;

  try_files $uri @passenger;

  location @passenger {
    passenger_enabled on;
    rails_env development;
  }

  ...
}
passenger_pre_start http://0.0.0.0:4000/status;

更多内容:
  • /usr/local/bin/ruby上存在Ruby二进制文件
  • gem 已安装在/usr/local/bundle


  • 但是,当我启动nginx服务时,出现以下错误
    It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:
    
    bundle install
    If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:
    

    乘客无法找到应用程序的 gem ,因为GEM_HOME和GEM_PATH设置错误

    Taken from passenger error page

    我试图在docker-entrypoint中手动设置环境变量GEM_HOMEGEM_PATH以更正gem路径,即/usr/local/bundle。但是它不起作用。

    我如何让乘客使用正确的 gem 。

    注意:我没有使用rvm
    提前致谢

    最佳答案

    出现此问题的原因是user_sandboxing by passenger

    由于我的应用程序目录归root所有,并且我没有在nginx中配置passenger_default_user,所以passenger盯着应用程序作为用户nobody和组nogroup
    我通过将应用目录的所有者更改为非root用户来解决此问题。

    注意:另外我还必须使用rvm而不是ruby:2.3.1基本镜像。

    关于ruby - $ GEM_HOME和$ GEM_PATH在旅客中设置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44589721/

    相关文章:

    arrays - Ruby 单词数组

    ruby - Mongoid::Errors::DocumentNotFound is raised even after rescuing

    django - 通过 nginx 为临时和生产站点提供服务?

    django - 如何使用 docker-compose 设置 nginx 和 django?

    ubuntu - 如何使用多个基础镜像构建一个 docker 镜像

    Ruby 实例评估

    ruby-on-rails - 如何从另一个参数引用参数 ('@param' 标签)?

    php - 是否可以在我的 droplet 上同时运行 PHP 和 JSP

    Nginx:缓冲链

    docker - 从Go挂起与Google API通话