RVM: a Cupid for Nginx and Phusion Passenger

I presented my work to my lab-group and it’s time to move the test applications in a stage aka “production” environment on my servers.
I’m fallen in love with Ruby Version Manager (RVM) which is running on my development virtual machine inside the Vaio.
Installing Ruby all the gems and the web server Nginx is so cool and easy, thanks God for RVM’s documentation. To run my rails application I’m using Nginx because it’s configuration is so dry and the engine is very fast.

Following the instruction here there is a little problem regarding … me :) I do not read the documentation… Wayne wrote about adding the right configuration in nginx/conf/nginx.conf if you are using rvm, but you know… the world is bad.

I need to replicate this configuration on different machines so I decided to create an old style patch to fix this annoing problem. You can download the patch here.

As reported in the Wayne’s documentation:

rvm ree
gem install passenger
patch -p0 < auto_set_rvm_env_with_nginx_phusion_passenger.patch
rvmsudo passenger-install-nginx-module

Note, I’m using Ree not the standard one and the original file is located:

.rvm/gems/ree-1.8.7-2010.01/gems/passenger-2.2.11/bin/passenger-install-nginx-module

7 Comments

  • Jones Lee wrote:

    I doesn’t work for me.

    rvm use ree –default

    and follow all your instructions, get nginx compiled and installed under

    ~/.rvm/rubies/ree-1.8.7–2010.01/nginx

    and then check the nginx.conf to make sure

    passenger_root /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11;
    passenger_ruby /Users/MAC/.rvm/rubies/ree-1.8.7–2010.01/bin/ruby;

    is there and then add a vhost

    server {
    listen 80;
    server_name http://www.spree.dev;
    root /Users/MAC/Sites/test/public; # <— be sure to point to ‘public’!
    passenger_enabled on;
    rails_env development;
    }

    add the 127.0.0.1 http://www.spree.dev into /private/etc/hosts

    then start the server using rvmsudo .rvm/rubies/ree-1.8.7–2010.01/nginx/sbin/nginx and browse http://www.spree.dev. And I got only error 403 Forbidden. Any suggestion?

  • Hello Jones,
    You must change the line
    passenger_ruby /Users/MAC/.rvm/rubies/ree-1.8.7–2010.01/bin/ruby;
    in
    passenger_ruby /home/ra/.rvm/bin/passenger_ruby;

    according to Wayne’s documentation and my patch for nginx’s configuration.
    Then… it’s easy if I share here my nginx configuration and my directory structure.
    I put everything (link) under nginx default html directory but you can put your suburi wherever you want.

    ra@ubuntu:~/deve$ ls –lh /opt/nginx/html/
    –rw-r–r– 1 root root 383 2010-04-02 05:17 50x.html
    lrwxrwxrwx 1 root root 26 2010-04-22 06:46 ProjectA -> /home/ra/deve/projecta/public
    lrwxrwxrwx 1 root root 27 2010-04-22 06:35 ProjectB -> /home/ra/deve/projectb/public
    –rw-r–r– 1 root root 1.4K 2010-04-13 04:08 favicon.ico
    –rw-r–r– 1 root root 151 2010-04-02 05:17 index.html
    lrwxrwxrwx 1 root root 31 2010-04-22 06:46 ProjectC -> /home/ra/deve/projectc/public
    lrwxrwxrwx 1 root root 27 2010-04-22 06:46 ProjectD -> /home/ra/deve/projectd/public

    ra@ubuntu:~/deve$ cat /opt/nginx/conf/nginx.conf

    #user ra;
    worker_processes 1;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;

    events {
    worker_connections 1024;
    }

    http {
    passenger_root /home/ra/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11;
    passenger_ruby /home/ra/.rvm/bin/passenger_ruby;
    # passenger_default_user ra;

    include mime.types;
    default_type application/octet-stream;

    #log_format main ‘$remote_addr — $remote_user [$time_local] “$request” ‘
    # ‘$status $body_bytes_sent “$http_referer” ‘
    # ’”$http_user_agent” “$http_x_forwarded_for“‘;

    #access_log logs/access.log main;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;

    server {
    listen 80;
    server_name localhost;
    # root /home/ra/www;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root html;
    index index.html index.htm;
    }

    location /ProjectC {
    passenger_enabled on;
    passenger_base_uri /ProjectC;
    rails_env development;
    }
    location /ProjectB {
    passenger_enabled on;
    passenger_base_uri /ProjectB;
    rails_env development;
    }

    location /ProjectA {
    passenger_enabled on;
    passenger_base_uri /ProjectA;
    rails_env development;
    }

    location /ProjectD {
    passenger_enabled on;
    passenger_base_uri /ProjectD;
    rails_env development;
    }
    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    location /doc {
    root /home/ra/rubyrem;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache’s document root
    # concurs with nginx’s one
    #
    #location ~ /\.ht {
    # deny all;
    #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    # HTTPS server
    #
    #server {
    # listen 443;
    # server_name localhost;

    # ssl on;
    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_timeout 5m;

    # ssl_protocols SSLv2 SSLv3 TLSv1;
    # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    }

  • Jones Lee wrote:

    I manage to get into the default rails’ index.html but hitting further return

    Passenger encountered the following error:
    The application spawner server exited unexpectedly: Unexpected end-of-file detected.
    Exception class:
    PhusionPassenger::Railz::ApplicationSpawner::Error
    Backtrace:
    # File Line Location
    0 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb 218 in ‘start’
    1 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb 262 in ‘spawn_rails_application’
    2 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb 126 in ‘lookup_or_add’
    3 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb 256 in ‘spawn_rails_application’
    4 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb 80 in ‘synchronize’
    5 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb 79 in ‘synchronize’
    6 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb 255 in ‘spawn_rails_application’
    7 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb 154 in ‘spawn_application’
    8 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb 287 in ‘handle_spawn_application’
    9 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb 352 in ‘__send__’
    10 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb 352 in ‘main_loop’
    11 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb 196 in ‘start_synchronously’
    12 /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/bin/passenger-spawn-server

    I think it must be due to some error with my passenger gem. The thing is no error logged in the log file

  • Jones Lee wrote:

    I got the error in error.log file:

    /Users/MAC/.rvm/gems/ree-1.8.7–2010.01/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:131: [BUG] Segmentation fault
    ruby 1.8.7 (2009–12-24 patchlevel 248) [i686-darwin10.3.0], MBARI 0x6770, Ruby Enterprise Edition 2010.01

    So I think it must be due to bug of ree…?

  • Jones Lee wrote:

    And I also got the same bug with 1.8.7-p249

    /Users/MAC/.rvm/gems/ruby-1.8.7-p249/gems/passenger-2.2.12/lib/phusion_passenger/abstract_server.rb:131: [BUG] Segmentation fault
    ruby 1.8.7 (2010–01-10 patchlevel 249) [i686-darwin10.3.0]

  • Jones Lee wrote:

    I got ruby-1.9.2 working with nginx finally :) . It must be due to some bug with ruby 1.8.7 on Mac OS X platform. Thanks for the guide

  • Hey Jones,
    happy to know it works.
    Please report a bug to PhusionPassenger, it can be of help to others.

Leave a Reply

Your email is never shared.Required fields are marked *