Phusion passenger creates only one app instance if two virtual hosts have the same DocumentRoot

71 views
Skip to first unread message

fant

unread,
May 3, 2012, 3:10:22 PM5/3/12
to Phusion Passenger Discussions
Hi

I happen to have two similar websites, one for individual customers,
and a very similar one for professional people.

These are based on Rails, use the same database, and 99% of the code
base is the same, so that it makes sense for me to deploy just once.

I expected that by creating two virtual hosts (with differing
environment variables in the vhost description), Phusion Passenger
would create two instances of my app.

That doesn't seem to be the case (only one instance is created, with
the environment variables set by which virtual host is called first
after restarting Apache).

I understand that Passenger relies on the vhost DocumentRoot to
identify a candidate Rails site, but maybe there's some way to
explicitly tell it what wep app instances it should launch, even if
they have the same DocumentRoot ?

Lori M Olson

unread,
May 4, 2012, 10:45:30 AM5/4/12
to phusion-...@googlegroups.com
Create a symlink to the original app and set up the second app's vhost by pointing it at the symlink's public path.  That works for us (only we have 10 vhosts).

If you use a capistrano deploy, you will need to set up an after hook to create that symlink.  Something like this (again, we have 10, so it's a loop):

  desc "Symlink the clones"
  task :custom_symlink, :roles => :app, :except => { :no_release => true } do
    on_rollback do
      (1..vhosts).to_a.each do |vhost|
        current_vhost_path = "#{deploy_to}/#{subdomain}#{vhost}"
        run "rm -f #{current_vhost_path}; ln -s #{previous_release} #{current_vhost_path}; true"
      end    
    end
    (1..vhosts).to_a.each do |vhost|
      current_vhost_path = "#{deploy_to}/#{subdomain}#{vhost}"
      run "rm -f #{current_vhost_path} && ln -s #{release_path} #{current_vhost_path}"
    end
  end

after "deploy:symlink", :custom_symlink

And, note that this is the paranoid version here, so if it's a rollback, we reset to the previous release.

Regards, Lori
Reply all
Reply to author
Forward
0 new messages