Search code examples
dnsapache2ubuntu-12.04web-hostinga-records

Multiple websites with multiple domain names on one single linux server


I would like to host multiple websites with different domain names on one apache server.

Lets say I have the following websites:

www.site1.com
www.site2.com
www.site3.com

I have got an ip address (such as: 89.x.x.x) which is linked to my /var/www directory where I can access from outside, and the structure would be:

/var/www/index.html // for www.site1.com
/var/www/site2/index.html // for www.site2.com
/var/www/site3/index.html // for www.site3.com

In my domain name configurations I have pointed the A-Record for each website to the same ip address. (I would like to avoid forwarding e.g. http://89.x.x.x/site2, because of the iframe problem that kills the website's responsiveness!)

I have followed some examples of virtualhost and htaccess configurations, but none of them worked!

As I am not very experienced in server configurations, I would appreciate for any suggestions to resolve this issue!

Thanks heaps!


Solution

  • You cannot setup name-based virtual hosts in an .htaccess file (too late to do anything about source directories there), so you should add the settings somewhere in the main apache configuration file(s).

    This following example is copied directly from https://httpd.apache.org/docs/2.2/vhosts/name-based.html:

    NameVirtualHost *:80
    
    <VirtualHost *:80> 
        ServerName www.domain.tld 
        ServerAlias domain.tld *.domain.tld 
        DocumentRoot /www/domain 
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName www.otherdomain.tld 
        DocumentRoot /www/otherdomain 
    </VirtualHost>