0

I don't get it and I hope you are able to help.

I have 3 domains and one server. I would like to get all 3 domains via port 80 on the right DirectoryRoot. But I'm unable to do that. With my current sites-available/default file they are all linking to the same directory (domain3).

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    ServerName www.domain1.tld
    ServerAlias *.domain1.tld
    DocumentRoot /var/www/domains/domain1/
    <Directory /var/www/domains/domain1/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>    

    ServerName www.domain2.tld
    ServerAlias *.domain2.tld
    DocumentRoot /var/www/domains/domain2/
    <Directory /var/www/domains/domain2>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>    

    ServerName www.domain3.tld
    ServerAlias *.domain3.tld
    DocumentRoot /var/www/domains/domain3/
    <Directory /var/www/domains/domain3>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>    

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

lechnerio
  • 884
  • 1
  • 16
  • 44

2 Answers2

1

You should do the following :

  • disable the default site by running this command :

rm /etc/apache2/sites-enabled/default

  • Then, in your /etc/apache2/sites-available directory, you should create 3 files for your 3 vhosts :

001-domain1

<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /var/www/domains/domain1
</VirtualHost>

002-domain2

<VirtualHost *:80>
ServerName www.domain2.tld
DocumentRoot /var/www/domains/domain2
</VirtualHost>

003-domain3

<VirtualHost *:80>
ServerName www.domain3.tld
DocumentRoot /var/www/domains/domain3
</VirtualHost>
  • Now, all you have to do is enable the 3 vhosts and restart apache. Run the following commands from your sites-available directory :

a2ensite 001-domain1

a2ensite 002-domain2

a2ensite 003-domain3

/etc/init.d/apache2 restart

Community
  • 1
  • 1
TehesFR
  • 140
  • 2
  • 15
0

You Must Use virtual Hosts here is The tutorial.

vhost

Try this

<VirtualHost *:80>
    DocumentRoot /var/www/domains/domain1/
    ServerName www.domain2.tld
    ServerAlias *.domain2.tld
</VirtualHost>
Denis Kohl
  • 739
  • 8
  • 13
  • Hey Denis, thanks for your answer. Unfortunately I can't get this to work. I adapted the Tutorial "Running several name-based web sites on a single IP address". domain2 is working, the rest is pointing to /var/www/domain1 - is there anything i can do to ensure everything reloads properly (or is it just restarting apache?) – lechnerio Jan 02 '15 at 09:15