Passenger错误地设置了$ GEM_HOME和$ GEM_PATH

时间:2017-06-16 12:51:42

标签: 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;

更多背景信息:

  • Ruby二进制文件位于/usr/local/bin/ruby
  • Gems安装在/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_HOME和GEM_PATH设置错误

Taken from passenger error page

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

如何让乘客使用正确的宝石套装。

注意:我没有使用rvm

提前致谢

1 个答案:

答案 0 :(得分:1)

此问题的原因是user_sandboxing by passenger

由于我的app目录由root拥有,而且我在nginx中没有配置passenger_default_user,因此乘客正在以用户nobody和群组nogroup

来启动应用程序

我通过将我的app目录的所有者更改为非root用户来修复此问题。

注意:我也不得不使用rvm而不是ruby:2.3.1基本图像。