trying to set up a sencond site

65 Views Asked by At

I'm having trouble setting up a sencond site on my apache2 server. I currently have one site up and running and its even live. However I have another site I am working on and am trying to host it locally. I've created a site-available file named newsite with the following

<VirtualHost *:80>
        ServerName newsite
        ServerAdmin webmaster@localhost

    DocumentRoot /var/www/newsite/
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/newsite/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            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>

I enable it with a2ensite newsite

I edit the host file 127.0.0.1 www.newsite.com

I've run a2ensite newsite

Now when I view the new site it works fine, but when I try view my original site i only get the newsite

If I disable new site (a2dissite newsite) the original site displays fine

Any help would be appreciated

1

There are 1 best solutions below

0
On

I think you have not set your ServerName and ServerAlias directives correctly.

For both your virtual hosts, they should be something like this

 ServerName newsite.com 
 ServerAlias www.newsite.com 
 ServerName oldsite.com 
 ServerAlias www.oldsite.com

What is happening currently is that you have setup a virtual host called newsite. If you do http://newsite/ : you will see the newsite, however you are doing www.newsite.com. Similarly, if you do http://oldsite/ (assuming it is setup the same way), you will also see oldsite.

When you do www.newsite.com, you DNS directs you to the loopback interface, however, when apache gets the request, it doesn't know what to do with it. So it just picks one. This would be no different from if you were to try and access simply by IP.

So solution is either you call http://newsite/ or fix your ServerName and ServerAlias directives.