Apache multiple domains setup

13,431

Solution 1

Ok, I figured it out. It was pretty silly. I just needed to uncomment this line so I would actually use all the virtual hosts:

NameVirtualHost *:80

Solution 2

You need to set up the two domains in two separate virtual hosts. Generally when I do this I like to split off an include directory full of virtual host files, with each file containing one virtual host.

<VirtualHost *:80>
  ServerName site1.com
  DocumentRoot "/var/www/site1"
</VirtualHost>
<VirtualHost *:80>
  ServerName site2.com
  DocumentRoot "/var/www/site2"
</VirtualHost>
Share:
13,431

Related videos on Youtube

Thread7
Author by

Thread7

Updated on October 10, 2022

Comments

  • Thread7
    Thread7 over 1 year

    I've got a pretty straightforward issue with a linux based Apache 2.2 server I am setting up. I want to setup two totally different domains on the same server. But it only serves content from the first tag! I've searched StackOverflow and read items at Apache.org but no luck.

    I followed the directions on Apache.org and put these two sections at the bottom of my http.conf file.

    <VirtualHost *:80>
        DocumentRoot /var/www/mydomain1
        ServerName sub1.mydomain1.com
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot /var/www/mydomain2
        ServerName sub2.mydomain2.com
    </VirtualHost>
    

    Now when I use a browser to go to: http://sub1.mydomain1.com it comes up fine. But if I go to http://sub2.mydomain2.com I still only get the content that located in /var/www/webfiles/mydomain1.

    I did many of the obvious things such as: - service httpd restart - I changed the order of the two entries in my httpd.conf and once again, it only serves the first one in the list. - One support doc I had Googled said to make sure to have the following entry point to a valid domain on your system. So I entered this (but it didn't change anything): ServerName sub2.mydomain2.com:80

    It must be something silly but I can't figure it out!