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.

i am trying to have multiple virtual hosts in apache setup in Ubuntu 10.04. I managed to setup a domain and a sub-domain, jivity.net and sonata.jivity.net using name based virtual hosts in apache2 and it works as intended. But when i try something like sonata-software.jivity.net , it redirects me to sonata.jivity.net . Its like the hyphen in sonata-software.jivity.net is not read by apache. Here is my virtual conf file for sonata-software.jivity.net :

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName sonata-software.jivity.net
    ServerAlias www.sonata-software.jivity.net
    SetEnv MAGE_RUN_CODE "sonata"
    SetEnv MAGE_RUN_TYPE "website"

    DocumentRoot /var/www/websites/jivity/sonata
    <Directory />
        Options FollowSymLinks
        AllowOverride all
    </Directory>
    <Directory /var/www/websites/jivity/sonata>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

sonata.jivity.net vconf file in /etc/apache2/sites-available/

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName sonata.jivity.net
    ServerAlias www.sonata.jivity.net
    SetEnv MAGE_RUN_CODE "sonata"
    SetEnv MAGE_RUN_TYPE "website"

    DocumentRoot /var/www/websites/jivity/sonata
    <Directory />
        Options FollowSymLinks
        AllowOverride all
    </Directory>
    <Directory /var/www/websites/jivity/sonata>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

I wanted to replace sonata.jivity.net with sonata-software.jivity.net I have enabled the site after placing this in the /etc/apache2/sites-available folder and restarted apache. How do i fix this so that i can have sonata-software.jivity.net also working? Thanks.

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

OK, 2nd attempt...

I'm going to take a wild guess here and wonder if you have the right document root for sonata-software.jivity.net.

Maybe you forgot to edit the DocRoot directory when you copied-and-edited the config from the existing sonata.jivity.net conf.

is this line from your config correct?

DocumentRoot /var/www/websites/jivity/sonata

or should it be something more like this:

DocumentRoot /var/www/websites/jivity/sonata-software

and same, of course, for the <Directory/var/www/websites/jivity/sonata>.

[later]

more on ServerName and ServerAlias...

if you want multiple domain names pointing at the same content, just make one virtual host and add as many ServerAliases as you want. e.g.

ServerName sonata-software.jivity.net
ServerAlias www.sonata-software.jivity.net
ServerAlias sonata.jivity.net
ServerAlias www.sonata.jivity.net

The ServerName is the "canonical name" of the site. It's common (but not required) to have the site configured so that any request for one of the aliases automatically redirected to the official URL.

You may have a redirection like this elsewhere in your apache config (search under /etc/apache2), or in a .htaccess file in the DocRoot.

share|improve this answer
    
Craig, you should add this as an edit to your original answer. –  Iain Sep 12 '11 at 14:36
    
why? if i had just made changes to the first answer, you'd be correct but this is a completely different answer, a completely different approach to solving the problem, unrelated to the first one. –  cas Sep 12 '11 at 14:54
    
That's the way we generally do things here - it's still just additional (potential) solutions. –  Iain Sep 12 '11 at 14:57
    
The document root is /var/www/websites/jivity/sonata its just the domain pointing to the folder that i want to change. When i started i had set the servename to sonata.jivity.net , i wanted to change this to sonata-software.jivity.net . Do i need to change the document root too? –  Nithin Sep 13 '11 at 7:32
    
you only need to change the DocRoot if you want the two sites to be have different content. If you want them to have the same content, then why have a separate vhost? why not just use a ServerAlias for the existing vhost? –  cas Sep 13 '11 at 14:36
show 2 more comments

have you symlinked it to the /etc/apache2/sites-enabled/ directory?

try:

sudo a2ensite sonata-software.jivity.net
share|improve this answer
1  
Yes, i did. And i got the msg that the site is enabled. After that i restarted apache using the command: sudo /etc/init.d/apache2 restart –  Nithin Sep 12 '11 at 7:09
    
Sorry about the edit. Was by mistake. –  Nithin Sep 12 '11 at 8:02
    
Nithin said: "If i disable the site: sonata.jivity.net using a2dissite command and restart apache, and then try to load sonata-software.jivity.net, it still redirects to sonata.jivity.net , except that it displays the default It works! page." –  Chris S Sep 12 '11 at 14:38
add comment

how about if you try removing the hyphen and just do sonatasoftware.jivity.net. make sure that your sites-available and sites-enable are also modified. if it works then maybe its just the hyphen that is somehow affecting the way apache is serving the pages.

Try disabling both sonata-software.jivity.net and sonata.jivity.net

a2dissite sonata.jivity.net
a2dissite sonata-software.jivity.net

Then restart apache2, then re-enable sonata-software.jivity.net

a2ensite sonata-software.jivity.net

See if it resolves your problem.

share|improve this answer
    
I tried with the hyphen for an other sub-domain, test-site.jivity.net and it worked. It was pointing to the right directory. And it dint work without the hyphen for sonatasoftware.jivity.net. I made the changes to Servename and server alias and reloaded apache. Still redirects to sonata.jivity.net –  Nithin Sep 12 '11 at 7:59
    
It might help if you can post your sonata.jivity.net conf file. If you add a specific IP address on your NameVirtualHost on apache2.conf and Virtualhost on the virtual host conf file this might work? –  jerichorivera Sep 12 '11 at 13:21
    
I have added the file in the original question. Kindly look at it.. –  Nithin Sep 13 '11 at 7:27
    
you have the same DocRoot for sonata-software and sonata. what you have to do is disable the sonata.jivity.net site then enable sonata-software.jivity.net. a2dissite sonata.jivity.net –  jerichorivera Sep 13 '11 at 10:11
    
I disabled all the sub-domains. Then restarted apache, enabled sonata-software.jivity.net and restarted apache again. It still redirects to sonata.jivity.net. TO be extra sure, i checked the sites-enabled folder every time i enabled and disabled a site. –  Nithin Sep 13 '11 at 14:17
show 2 more comments

Have you configured properly your DNS?

Check your access log, you should read what's happening.

Rename sonata-software to something completely different, reconfigure the DNS and restart Apache (this may take some time for the cache to be refreshed).

share|improve this answer
    
My DNS is configured to accept wildcards using a '*' entry under DNS records. jivity.net is my primary domain, sonata.jivity.net is a sub domain, and it works perfectly. Instead of sonata, i wanted to change it to sonata-software. I added an other record test-site.jivity.net and it worked. –  Nithin Sep 12 '11 at 7:46
    
I looked at the log files too. Dint find anything there. –  Nithin Sep 12 '11 at 8:15
    
It sounds to me like a DNS-related problem, but I'm not a DNS expert, so I'll quit here my contribution. Good luck! –  AndrewQ Sep 12 '11 at 8:27
    
@Nithin So, do you have a DNS entry for sonata-software? –  Jason Taylor Sep 12 '11 at 14:58
    
The domain, jivity.net is registered with godaddy. In the godaddy dns panel, i have added records to point to an ip. The server is an amazon ec2 instance. This is dns configuration i was talking about? Is there something more i need to add? –  Nithin Sep 13 '11 at 7:27
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.