passenger snippets

Vlad deployment recipe for Phusion Passenger

Tagged vlad, phusion, passenger, apache, deployment  Languages ruby
#
# General configuration
#
#set :ssh_flags,             '-p 110000'
set :application,           'app.xxx'
set :domain,                'x.x.x.x'
set :deploy_to,             '/var/www/app.xxx'
set :revision,              'master'
set :repository,            '/var/lib/git/repositories/app.xxx/'


namespace :vlad do
  set :app_command, "/etc/init.d/apache2"
 
  desc 'Restart Passenger'
  remote_task :start_app, :roles => :app do
    run "touch #{current_release}/tmp/restart.txt"
  end
  
  desc 'Restarts the apache servers'
  remote_task :start_web, :roles => :app do
    run "sudo #{app_command} restart"
  end
end

How to hide X-Powered-By and Server headers

Tagged servertokens, server, x-powered-by, mod_rails, passenger, apache, apache2, headers  Languages apacheconf

First enable the mod_headers module:

sudo a2enmod headers

Then add this to your apache2.conf:

# Hide X-Powered-By and Server headers
Header always unset "X-Powered-By"
ServerTokens Prod
ServerSignature Off

Now restart Apache:

/etc/init.d/apache2 force-reload

This is security through obscurity at it's finest...

Paperclip plugin + Phusion Passenger + path problem

Tagged paperclip, apache, phusion, passenger  Languages ruby

In config/initializers/paperclip.rb put:

if RAILS_ENV == "development"
  Paperclip.options[:command_path] = '/opt/local/bin/'
else
  Paperclip.options[:command_path] = '/usr/bin/'
end

Note image_magick_path is deprecated alias of command_path.

Fixing Phusion Passenger "Error during failsafe response: closed stream"

Tagged passenger, gotcha  Languages bash

This error most probably means that Passenger doesn't have read access to all files:

Error during failsafe response: closed stream
[Thu Aug 13 01:40:05 2009] [error] [client 88.115.162.70] Premature end of script headers: 
[ pid=12581 file=Hooks.cpp:516 time=2009-08-13 01:40:05.753 ]:
  Backend process 18230 did not return a valid HTTP response. It returned: [Status]
*** Exception NoMethodError in application (undefined method []=' for nil:NilClass) (process 18230):

To fix it run:

chown -R xxx.www-data /var/www/xxx

Ruby Enterprise Edition symlinks

Tagged ree, passenger, ruby, symlinks  Languages bash

This will save you from playing with PATH:

sudo ln -fs /opt/ruby-enterprise-1.8.6-20090610 /opt/ruby-enterprise
sudo ln -fs /opt/ruby-enterprise/bin/gem /usr/bin/gem
sudo ln -fs /opt/ruby-enterprise/bin/irb /usr/bin/irb
sudo ln -fs /opt/ruby-enterprise/bin/rake /usr/bin/rake
sudo ln -fs /opt/ruby-enterprise/bin/rails /usr/bin/rails
sudo ln -fs /opt/ruby-enterprise/bin/ruby /usr/bin/ruby

Passsenger.conf is also simplified:

LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5
PassengerRuby /opt/ruby-enterprise/bin/ruby

How to install Nginx from source, Ruby Enterprise Edition, and Phusion Passenger

Tagged nginx, install, passenger, ree  Languages bash

Ruby Enterprise Edition:

cd /usr/local/src
wget thttp://rubyforge.org/frs/download.php/66162/ruby-enterprise-1.8.7-2009.10.tar.gz
tar zxvf ruby-enterprise-1.8.7-2009.10.tar.gz
./ruby-enterprise-1.8.7-2009.10/installer

ln -fs /opt/ruby-enterprise-1.8.7-2009.10 /opt/ruby-enterprise/

Nginx:

wget -P http://sysoev.ru/nginx/nginx-0.7.63.tar.gz
tar -xzf nginx-0.7.63.tar.gz

Phusion Passenger:

gem install passenger
/opt/ruby-enterprise/bin/passenger-install-nginx-module --auto --nginx-source-dir=/tmp/nginx-0.7.63 --prefix=/opt/nginx --extra-configure-flags=--with-http_ssl_module