Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The problem is simple, http://example.com and http://www.example.com aren't the same sites. The problem is surely in my VHost configuration:

PassengerMinInstances 5 PassengerPoolIdleTime 0

<VirtualHost *:80>
        ServerAdmin webmster@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /home/someuser/www/example.com/public_html/public
        <Directory /home/someuser/www/example.com/public_html/public>
                AllowOverride all
                Options -MultiViews
        </Directory>
        ErrorLog /home/someuser/www/example.com/logs/error.log
        CustomLog /home/someuser/www/example.com/logs/access.log combined
        RailsBaseURI /
        PassengerSpawnMethod smart
</VirtualHost>

I have also removed any modules that weren't causing start up errors, these are the ones that are being loaded:

# ls mods-enabled
alias.conf  alias.load  authz_default.load  authz_groupfile.load  authz_host.load  authz_user.load
share|improve this question

migrated from stackoverflow.com Jul 28 '11 at 13:55

This question came from our site for professional and enthusiast programmers.

1  
If you're not going to give your real web address, use example.com as it's guaranteed by RFC 2606 not to be anyone else's real website –  Gareth Jul 28 '11 at 6:52
    
@Gareth sorry, noted and I shall edit. –  Emil Ahlbäck Jul 28 '11 at 7:03
add comment

3 Answers

There are 2 big things to check here:

  1. Do both domains resolve to the same IP address:

    Try host example.com and host www.example.com from your command line to see if the different requests are being routed to the same server.

    If not, you'll need to update the DNS for your domain to be consistant

  2. Is Apache getting confused? For any given request, Apache will use the first virtual host in its config which has a matching ServerName or ServerAlias. Check that you don't have conflicting vhost configuration

share|improve this answer
    
They resolve to the same IP address. I'll go through my configuration and check for any conflicts. Thanks. –  Emil Ahlbäck Jul 28 '11 at 7:08
add comment

Prefacing my answer with "I don't know anything about ruby".

You've stated http://example.com and http://www.example.com aren't the same sites but your vhost configuration is saying that they are.

ServerName example.com
ServerAlias www.example.com

Those directives are saying that this vhost will answer for both of those names. So, it souds like you just need to break out the www.example.com into its own vhost with its own ServerName directive.

<VirtualHost *:80>
        ServerAdmin webmster@example.com
        ServerName example.com
        DocumentRoot /home/someuser/www/example.com/public_html/public
        ....other stuff....
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin webmster@example.com
        ServerName www.example.com
        DocumentRoot /home/someuser/www/www.example.com/public_html/public
        ....other stuff....
</VirtualHost>

If there is some magic in the way ruby handles vhosts, then my answer is useless :)

share|improve this answer
    
Sorry, lack of details from my part. They are supposed to be the same sites, but there seem to be two different apps (in ruby on rails speak) running. Their session IDs are different (or at least sessions aren't shared, logging in on one of them doesn't mean I'm logged in on the other one). –  Emil Ahlbäck Jul 28 '11 at 14:29
    
Aaah, ok. Got it. In that case my answer is way off, and I don't know ;) –  Alex Jul 28 '11 at 14:35
    
@eml - Oh, from your description it sounded like your app was only responding to one of those domains. What you mean is, you are getting the same app from both domains but they aren't sharing the same session. That totally changes the question, and it might have been relevant on StackOverflow after all –  Gareth Jul 28 '11 at 16:23
    
@Gareth, actually I don't know if they are in fact the same app. There are some differences at least: sessions aren't shared, and the favicon (not specified in html as browser find those themselves I've heard) are NOT shared. The favicon is shown on the www-version, not on he no-www-version. –  Emil Ahlbäck Jul 29 '11 at 11:44
add comment
up vote 0 down vote accepted

This vhost config solved my problem:

<VirtualHost *:80>
        ServerName example.com
        ServerAlias *.example.com
        DocumentRoot /home/someuser/www/example.com/public_html/public
        <Directory /home/someuser/www/example.com/public_html/public>
                Options FollowSymLinks
                AllowOverride none
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog /home/someuser/www/example.com/logs/error.log
        CustomLog /home/someuser/www/example.com/logs/access.log combined
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
        RewriteRule ^(.*)$ http://example.com$1 [R=301,L]
</VirtualHost>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.