无法启动乘客监督,但乘客已安装

时间:2014-07-08 08:46:33

标签: ruby-on-rails nginx passenger vagrant chef

我想在ubuntu 12.04 VM(流浪者盒)上设置带有乘客支持的nginx。因此,我创建了以下厨师食谱配方(https://github.com/i42n/wrapper-nginx-passenger/blob/master/recipes/default.rb):

#
# Cookbook Name:: wrapper-nginx-passenger
# Recipe:: default
#
# Copyright 2014, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute

apt_repository 'nginx-passenger' do
  uri          'https://oss-binaries.phusionpassenger.com/apt/passenger'
  distribution node['lsb']['codename']
  components   ['main']
  keyserver    'keyserver.ubuntu.com'
  key          '561F9B9CAC40B2F7'
end

# install nginx which contains passenger support
package "nginx-extras"
package "passenger"

# define nginx service as the nginx::passenger recipe restarts the service
# and fails if the service does not exist
service 'nginx' do
  supports :status => true, :restart => true, :reload => true
  action   :start
end

# installs the passenger gem
include_recipe "nginx::passenger"

# create server config template in nginx config directory
template "/etc/nginx/sites-available/plantasy" do
  source "plantasy.erb"
  mode 0644
  owner "root"
  group "root"
end

# symlink the config to the active sites directory
link "/etc/nginx/sites-enabled/plantasy" do
  to "/etc/nginx/sites-available/plantasy"
end

它遵循乘客安装指南:https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#install_add_apt_repo

但是如果我尝试启动nginx,我会收到以下错误:

vagrant@vagrant:/etc/nginx/conf.d$ sudo service nginx restart
 * Restarting nginx nginx
nginx: [alert] Unable to start the Phusion Passenger watchdog because its executable (/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/agents/PassengerWatchdog) does not exist. This probably means that your Phusion Passenger installation is broken or incomplete, or that your 'passenger_root' directive is set to the wrong value. Please reinstall Phusion Passenger or fix your 'passenger_root' directive, whichever is applicable. (-1: Unknown error)
   ...done.

如果nginx在乘客支持下没有正确编译,这实际上似乎是一个常见的错误。但是,如果我检查nginx模块,我的nginx确实有乘客支持:

vagrant@vagrant:~$ nginx -V
nginx version: nginx/1.6.0
TLS SNI support enabled
configure arguments: --with-cc-opt= --with-ld-opt= --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_spdy_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/headers-more-nginx-module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-auth-pam --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-cache-purge --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-dav-ext-module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-development-kit --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-echo --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/ngx-fancyindex --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-http-push --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-lua --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-upload-progress --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-upstream-fair --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/ngx_http_substitutions_filter_module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/passenger/ext/nginx

错误实际上是正确的。正在寻找nginx启动的文件/文件夹乘客不存在:

vagrant@vagrant:/etc/nginx/conf.d$ ls -l /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45
total 196
-rw-r--r--  1 vagrant root 80232 Jul  7 13:38 CHANGELOG
-rw-r--r--  1 vagrant root 15919 Jul  7 13:38 CONTRIBUTING.md
-rw-r--r--  1 vagrant root  1035 Jul  7 13:38 CONTRIBUTORS
-rw-r--r--  1 vagrant root   363 Jul  7 13:38 INSTALL.md
-rw-r--r--  1 vagrant root  1056 Jul  7 13:38 LICENSE
-rw-r--r--  1 vagrant root  2880 Jul  7 13:38 README.md
-rw-r--r--  1 vagrant root  1814 Jul  7 13:38 Rakefile
-rw-r--r--  1 vagrant root  2345 Jul  7 13:38 Vagrantfile
drwxr-xr-x  2 vagrant root  4096 Jul  7 13:38 bin
drwxr-xr-x  2 vagrant root  4096 Jul  7 13:38 build
-rwxr-xr-x  1 vagrant root   287 Jul  7 13:38 configure
drwxr-xr-x  4 vagrant root  4096 Jul  7 13:38 debian.template
drwxr-xr-x  4 vagrant root  4096 Jul  7 13:38 dev
drwxr-xr-x  5 vagrant root  4096 Jul  7 13:38 doc
drwxr-xr-x  2 vagrant root  4096 Jul  7 13:38 download_cache
drwxr-xr-x 10 vagrant root  4096 Jul  7 13:38 ext
drwxr-xr-x  3 vagrant root  4096 Jul  7 13:38 helper-scripts
drwxr-xr-x  3 vagrant root  4096 Jul  7 13:38 lib
drwxr-xr-x  2 vagrant root  4096 Jul  7 13:38 man
drwxr-xr-x  3 vagrant root  4096 Jul  7 13:38 node_lib
-rw-r--r--  1 vagrant root  6514 Jul  7 13:38 npm-shrinkwrap.json
-rw-r--r--  1 vagrant root   722 Jul  7 13:38 package.json
-rw-r--r--  1 vagrant root  1243 Jul  7 13:38 passenger.gemspec
drwxr-xr-x  4 vagrant root  4096 Jul  7 13:38 resources
drwxr-xr-x  2 vagrant root  4096 Jul  7 13:38 rpm
drwxr-xr-x 10 vagrant root  4096 Jul  7 13:38 test

我有默认nginx.conf/etc/nginx/conf.d/passenger.conf如下所示:

vagrant@vagrant:/etc/nginx/conf.d$ cat /etc/nginx/conf.d/passenger.conf 
passenger_root /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45;
passenger_ruby /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby;
passenger_max_pool_size 6;
passenger_spawn_method smart-lv2;
passenger_buffer_response on;
passenger_min_instances 1;
passenger_max_instances_per_app 0;
passenger_pool_idle_time 300;
passenger_max_requests 0;

如果我删除passenger.conf nginx启动没有错误,并提供默认测试页。因为可以预期的乘客不起作用。

我的乘客app nginx配置如下所示:

vagrant@vagrant:~$ cat /etc/nginx/sites-enabled/plantasy 
# Only for development purposes.
# For production environment, set it accordingly (i.e. production)
# Remove this line when you upload an actual application.
# For * TESTING * purposes only.
passenger_app_env development;

server {
  listen 8080;
  server_name example.com;
  passenger_enabled on;
  passenger_ruby /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby;
  root /home/vagrant/app/public;
}

如果我尝试访问此页面,我会收到403:

vagrant@vagrant:~$ curl localhost:8080
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.6.0</center>
</body>
</html>

Ruby已正确安装:

vagrant@vagrant:~$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

此外还安装了乘客宝石。

vagrant@vagrant:~$ gem list passenger

*** LOCAL GEMS ***

passenger (4.0.45)

我真的不知道出了什么问题。我查看了this thread,但正如您在上面看到的那样,我有nginx出现在乘客的支持下。这只是乘客二进制文件丢失了吗?

任何想法如何解决这个问题?

在有人建议之前:我不想自己编译nginx。我想使用apt存储库中的版本,因为它可以极大地提高vagrant VM设置的性能。

2 个答案:

答案 0 :(得分:1)

您的passenger_root指令不正确。您可以按照以下指南找到正确的值: https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#inserting_passenger_root_for_apt

答案 1 :(得分:0)

检查passenger-install-nginx-module是否已正确安装。

'which passenger-install-nginx-module'

如果没有安装,请尝试:

rvmsudo passenger-install-nginx-module

这适用于rvm用户。会解决问题