0

I'm serving several PHP sites on Apache2. Now I'm trying to also serve a Rails app with mod_passenger.

Thing is: when I set mod_passenger to listen on railsapp.com:81, it works. Also the PHP sites work. Now if I set railsapp.com:80, ALL the sites show the rails app, no PHP sites any more!

# cat phpsite.com
<VirtualHost *:80>
    ServerAdmin [email protected] 
    ServerName phpsite.com
    DocumentRoot /var/www/phpsite.com

    <Directory /var/www/phpsite.com>
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>

# cat railsapp.com
<VirtualHost railsapp.com:81>
    ServerName railsapp.com
    DocumentRoot /var/railsapp.com/public   
    <Directory /var/railsapp.com/public>
         AllowOverride all
         Options -MultiViews
    </Directory>
</VirtualHost>

This way, the rails app works on port 81 and the other sites work on their "normal" address, i.e. without specifying a port. When I change the second file to this:

# cat railsapp.com
    <VirtualHost railsapp.com:80>        #<-------------- 81 -> 80
        ServerName railsapp.com
        DocumentRoot /var/railsapp.com/public   
        <Directory /var/railsapp.com/public>
             AllowOverride all
             Options -MultiViews
        </Directory>
    </VirtualHost>

then ALL the sites show the railsapp, although it clearly states to only listen on railsapp.com:80.

Any ideas?

Thank you, MrB

1 Answer 1

0

Your VirtualHost declaration is a bit scary. You really do not want the host name 'railsapp.com' in the VirtualHost tag. You want an IP address, or a wildcard. I suggess you set all your VirtualHosts to:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName railsapp.com
  ServerAlias www.railsapp.com
...

</VirtualHost>

<VirtualHost *:80>
  ServerName phpsite.com
  ServerAlias www.phpsite.com
...

</VirtualHost>

The ServerAlias is important, as in the config you provided the prepending www.*.com sites would go to the DEFAULT VirtualHost, which is the first VirtualHost for that interface:port combination. This is likely why they are hitting the rails app.

Edit: To be more clear, any connection to an IP:Port combination that does not match the ServerName/ServerAlias of a VirtualHost will go to the default VirtualHost for that interface. For this reason, I typically have a config file (in debian, I put this in 000-defualt.conf in sites-enabled) that grabs all non-matching traffic and sends it to a default page, like this:

<VirtualHost 10.1.2.3:80>

  DocumentRoot /var/www/bad-hostname/
  <Directory /var/www/bad-hostname>
    ....
  </Directory>

</VirtualHost>

This helps debugging name-based virtual hosting as well as keeps people who hit my IP without a Host header from seeing ANY of the content on the server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .