Ruby on Rails, nginx, passenger on production serv

2020-03-31 03:57发布

问题:

I installed:

  • Centos 6
  • Ruby 1.9.3-rc1
  • Passenger gem and passenger nginx module ( compiled against own source 1.1.6)
  • Installed rails 3.1.0
  • Made /srv
  • Did rails new test
  • bundle install
  • made vhost for passenger inside nginx based on example /srv/test/public
  • service nginx stop && service nginx start
  • ruby app loads okay index.html is shown but then...

Upon Clicking the "check application environment" link that is inside the default /public/index.html I get this error

cannot load such file -- rubygems/path_support

Question: Anyone know how I can resolve the cannot load such file -- rubygems/path_support    error?

Full error post below

Ruby (Rack) application could not be started A source file that the application requires, is missing. It is possible that you didn't upload your application files correctly. Please check whether all your application files are uploaded. A required library may not installed. Please install all libraries that this application requires. Further information about the error may have been written to the application's log file. Please check it in order to analyse the problem.

Error message: cannot load such file -- rubygems/path_support

Exception class: LoadError

Application root: /srv/test

Backtrace:

# File Line Location
0 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems.rb 392 in 'paths'
1 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems.rb 413 in 'path'
2 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 381 in 'dirs'
3 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 267 in '_all'
4 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 409 in 'each'
5 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 441 in 'find'
6 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb 441 in 'find_by_path'
7 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems.rb 203 in 'try_activate'
8 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 58 in 'rescue in require'
9 /usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 35 in 'require'
10 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/utils.rb 241 in 'prepare_app_process'
11 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb 155 in 'block in initialize_server'
12 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/utils.rb 572 in 'report_app_init_status'
13 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb 153 in 'initialize_server'
14 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb 204 in 'start_synchronously'
15 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb 180 in 'start'
16 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/rack/application_spawner.rb 128 in 'start'
17 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb 253 in 'block (2 levels) in spawn_rack_application'
18 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb 132 in 'lookup_or_add'
19 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb 246 in 'block in spawn_rack_application'
20 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb 82 in 'block in synchronize'
21 prelude> 10:in 'synchronize'
22 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb 79 in 'synchronize'
23 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb 244 in 'spawn_rack_application'
24 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb 137 in 'spawn_application'
25 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb 275 in 'handle_spawn_application'
26 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb 357 in 'server_main_loop'
27 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb 206 in 'start_synchronously'
28 /usr/local/rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/helper-scripts/passenger-spawn-server 99 in ''

回答1:

I had a similar problem, though I had rvm and ruby installed only for one user. For me, the solution was to check that the application files were owned by the same user for which ruby was installed.

http://www.modrails.com/documentation/Users%20guide%20Nginx.html#user_switching



回答2:

In my case, I also met this problem:
( My environment: Centos 5.8, rbenv 1.9.3p327, passenger 3.0.19, nginx( compiled and installed by passenger) . I googled around but didn't find any direct answer ( keyword: rbenv, passenger, cannot load such file -- rubygems/path_support), so I write my solution here.

I have checked and set nginx user to root, not works. and changed all the privileges of gem folder to 777. not works.

finally I got the solution: add these 2 lines of code to your Nginx config file:

passenger_default_user root;
passenger_default_group root;

so now your nginx config file looks like:

# /opt/nginx/config/nginx.conf
user  root;  # seems this line of code doesn't take effect.
http {
  passenger_root /root/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/passenger-3.0.19;
  passenger_ruby /root/.rbenv/versions/1.9.3-p327/bin/ruby;

  # these lines are the key!!!
  passenger_default_user root;
  passenger_default_group root;

  server {
    listen 80;
    root <your_rails_project_public_folder>;
    passenger_enabled on;
  }
}


回答3:

I had a same problem. Timo is right.

your application must set /home/rvm_user/ directory.

example:

# vi /etc/conf/httpd.conf
LoadModule passenger_module
/home/rvm_user/.rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /home/rvm_user/.rvm/gems/ruby-1.9.3-rc1/gems/passenger-3.0.9
PassengerRuby /home/rvm_user/.rvm/wrappers/ruby-1.9.3-rc1/ruby

<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /home/rvm_user/your_application/public
<Directory /home/rvm_user/your_application/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>

# chmod 755 /home/rvm_user/

# /etc/rc.d/init.d/httpd restart