0

I want to run multiple domains on my server (only two at the moment). I already changed both nameservers to point to my server.

In the apache2.conf file I enabled "included sites-enabled".

My ports.conf file looks as follows

NameVirtualHost *:80 Listen 80 Listen 443 <VirtualHost xx.xx.xx.xx:443> SSLEngine On SSLCertificateFile /etc/apache2/ssl/apache.pem SSLCertificateKeyFile /etc/apache2/ssl/apache.key ServerAdmin [email protected] ServerName firstDomain.com DocumentRoot /var/www/ ErrorLog /var/log/error.log CustomLog /var/log/access.log combined </VirtualHost> 

This is the setting for my main page.

My httpd.conf file looks like this

ServerName firstDomain.com <VirtualHost xx.xx.xx.xx:80> ServerAdmin [email protected] ServerName firstDomain.com DocumentRoot /var/www/ ErrorLog /var/log/error.log CustomLog /var/log/access.log combined </VirtualHost> <VirtualHost *:80> ServerName secondDomain.com ServerAlias *.secondDomain.com DocumentRoot /home/user/www/secondDomain.com/htdocs </VirtualHost> Options -Indexes All FollowSymLinks MultiViews 

Last but not least my "secondDomain" file in "sites-avaiable"

<VirtualHost secondDomain.com> ServerAdmin [email protected] ServerName secondDomain.com # Indexes + Directory Root. DirectoryIndex index.html DocumentRoot /home/user/www/secondDomain/htdocs/ # CGI Directory ScriptAlias /cgi-bin/ /home/user/www/seoncDomain/cgi-bin/ <Location /cgi-bin> Options +ExecCGI </Location> # Logfiles ErrorLog /home/user/www/secondDomain/logs/error.log CustomLog /home/user/www/secondDomain/logs/access.log combined </VirtualHost> 

I also get an error message, everytime I restart the apache server, saying that VirtualHosts xx.xx.xx.xx:80 overlaps with VirtualHosts xx.xx.xx.xx:80.

When I call my secondDomain.com only the firstDomain.com pops up. It seems like the mapping is wrong.

apachectl -t output:

[warn] VirtualHost xx.xx.xx.xx:80 overlaps with VirtualHost xx.xx.xx.xx:80, the first has precedence, perhaps you need a NameVirtualHost directive Syntax OK 

apache2ctl -S output:

[Wed Feb 29 02:05:17 2012] [warn] VirtualHost xx.xx.xx.xx:80 overlaps with VirtualHost xx.xx.xx.xx:80, the first has precedence, perhaps you need a NameVirtualHost directive VirtualHost configuration: 127.0.0.1:* secondDomain.com (/etc/apache2/sites-enabled/secondDomain.com:1) xx.xx.xx.xx:443 firstDomain.com (/etc/apache2/ports.conf:12) xx.xx.xx.xx:80 firstDomain.com (/etc/apache2/httpd.conf:3) wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server secondDomain.com (/etc/apache2/httpd.conf:11) port 80 namevhost secondDomain.com (/etc/apache2/httpd.conf:11) port 80 namevhost firstDomain.com (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost firstDomain.com (/etc/apache2/apache2.conf:241) port 80 namevhost secondDomain.com (/etc/apache2/apache2.conf:249) Syntax OK 

Wordpress is installed through apt-get. I have a symlink in /var/www/ which points to /usr/share/wordpress and activated in /etc/apache2/sites-available and a2ensite.

2
  • can you run apachectl -t and paste any errors you see? Commented Feb 28, 2012 at 10:15
  • edited post with apachectl -t output. Commented Feb 28, 2012 at 11:34

2 Answers 2

4

You have a NameVirtualHost directive, but you're not using it. You're specifying the IP address and/or the hostname in your <VirtualHost> declaration - that's not what you want.

Change:

<VirtualHost xx.xx.xx.xx:80> 

and

<VirtualHost secondDomain.com> 

To both be simply:

<VirtualHost *:80> 
8
  • This fixed the error output, when calling apachectl -t, but somehow now the firstdomain.com maps to my wordpress install, which lies in www/wordpress, although that's not what I want. Therefore I changed the values back to the IP address. I think something is completely messed up with my settings. Commented Feb 28, 2012 at 19:10
  • Where's your wordpress configured? And what output do you get from apache2ctl -S? Commented Feb 28, 2012 at 19:13
  • edited first post with output. Commented Feb 29, 2012 at 1:05
  • @cherrun You have an three total vhosts that are configured to be firstdomain.com; the one in your httpd.conf file (which is empty by default in the Debian packaging that you're using) is getting precedence over the ones in apache2.conf and sites-available/default. Get rid of the copies that shouldn't exist, and set all port 80 vhosts to the correct host specification as outlined in my answer. You have vhost definitions sprinkled all over the place: ports.conf, httpd.conf, and apache2.conf, which is making things a lot more complicated than they need to be. Commented Feb 29, 2012 at 1:29
  • Which one is the correct file to write all the vhosts to? Is it alright that the ports.conf only have the Listen 80 and 443 option without specifying further vhosts? Commented Feb 29, 2012 at 13:27
1

You may try next:

  1. Move firstDomain.com virtual host declaration to sites-available/firstDomain.
  2. Remove everything from httpd.conf (you may try to define ServerName in apache2.conf)
  3. Ensure that you have sites-available/firstDomain and sites-available/secondDomain symlinked to sites-enabled/firstDomain and sites-enabled/secondDomain respectively.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.