Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache multiple domains setup

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!

like image 324
Thread7 Avatar asked Jun 21 '12 18:06

Thread7


2 Answers

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
like image 126
Thread7 Avatar answered Oct 18 '22 16:10

Thread7


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>
like image 40
hsanders Avatar answered Oct 18 '22 14:10

hsanders