Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Running Ubuntu 12.04 LTS, Apache2.2.22. Running this on a home server through one IP. Problem running virtual hosts. I have a domain name registered with godaddy. lets say mysite.com, goal is to have www.mysite.com and test.mysite.com. Currently only www.mysite.com is working, if I try test.mysite.com it displays the content of www.mysite.com(I did make sure the content of both sites is different). I have created two files in sites-available and ran the appropriate A2ensite www.mysite.com and A2ensite test.mysite.com. Below are the two virtual host files:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/test.mysite.com
    ServerName mysite.com
    ServerAlias test.mysite.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/test.mysite.com/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all         
    </Directory>

Here is www.mysite.com virtual host file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www.mysite.com
    ServerName mysite.com
    ServerAlias www.mysite.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www.mysite.com/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

On Godaddy domain management I have @ pointed to my public IP, I have an "A" record for www pointed to my public IP and I have a "A" record for test pointed to public ip. Any help to what I am doing wrong would be greatly appreciated. Thank you all.

share|improve this question

migrated from serverfault.com Sep 18 '13 at 2:35

This question came from our site for professional system and network administrators.

    
You don't need the A records for www and test if you have the default (@) pointing there, it's just redundant. Doesn't hurt either way. –  Chris S Sep 18 '13 at 2:34
add comment

4 Answers

For test.mysite.com set ServerName to test.mysite.com

share|improve this answer
    
Thanks for the response, I just tried and no difference. –  fritzah Sep 18 '13 at 2:21
add comment

Since I can't comment, I will update what fixed the problem so others may find it helpful. It was a case of user error. I overlooked checking the sites-enabled folder to view which sites were enabled, and test.mysite.com was not there. I ran a2ensite test.mysite.com and restarted Apache and now it is working.

share|improve this answer
    
You can use the "contact us" link to merge your accounts. –  Journeyman Geek Sep 18 '13 at 6:18
add comment
  1. Make sure you have virtual hosts enabled in httpd.conf:

    NameVirtualHost *:80
    NameVirtualHost *:443
    
  2. ServerName in each VirtualHost directive must reflect the hostname it will be serving.

    ServerAlias should only be used when necessary. It should be additional name(s) the virtual host should respond to. It should not be the same as ServerName.

    The first VirtualHost directive will be used as the default when no other matches or the client does not provide a Host: header (older versions of HTTP don't require this header).

  3. The <Directory /> directive should probably be in the global configuration instead of being repeated in every virtual host configuration.. Works either way, I'm just a stickler for clean configs.

Make sure you're restarting Apache after any changes to the configuration file(s).

Edit:
I saw your attempt at responding, indicating that you're receiving an error that you have no VirtualHosts configured on *:80. Your virtual hosts are in an include file, so it must be getting included in the configuration for some reason.

My first guess is that the include path is wrong (though I would think that'd come from the package that way, so it aught to be right - of course the various Linux distributions make Apache so needlessly complex that it drives me straight up the wall... but I digress). Usually a relative path is based in Apache's install base. Since I'm not sure if that's correct, and it's apparently not loading the files, you might want to change that to the absolute path and see what happens (ie /opt/apache22/enabled-sites, or whatever it is on your system).

Also, you can comment out the line that's there with a standard hash (#), then add your own, so you don't lose the original configuration.

share|improve this answer
add comment

The right configs should be this for each sites

for test.mysite.com

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/test.mysite.com
    ServerName test.mysite.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/test.mysite.com/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all         
    </Directory>

For mysite.com

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www.mysite.com
    ServerName mysite.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www.mysite.com/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

The ServerAlias work like this.

If you want the same virtualhost to have other addres than you use ServerAlias Example:

ServerName  mysite.com
ServerAl   www.mysite.com
share|improve this answer
add comment

Your Answer

 
discard

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