$GEM_HOME 和 $GEM_PATH 在 Passenger 中设置错误

$GEM_HOME and $GEM_PATH are wrongly set in 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;

更多上下文:

但是当我启动 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 设置错误

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

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

注意:我没有使用rvm

提前致谢

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

由于我的应用程序目录由 root 拥有,并且我没有在 nginx 中配置 passenger_default_user,passenger 正在以用户 nobody 和组 nogroup

的身份启动应用程序

我通过将我的应用程序目录的所有者更改为非根用户来解决此问题。

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