1

First of all, sorry for my imperfect English. But let me explain my problem with apache vhosts.

Example: My servername is example.de (/etc/hostname). If I configure for this specific domain my vhost won´t work. It seems apache uses the default-vhost. But I need the default-vhost for pages that are not active on my server. So I can´t use it for the domain example.de

I need a solution for following problem:

  • example.de - Should point to /var/www/example (This doesn´t work, because /etc/hostanme)
  • example2.de - Should point to /var/www/example2 (This works)
  • domain-i-got-but-not-active.de Should point to /var/www/default (This works, but also catches example.de)

I can´t change my hostname, because mails sent from my server will be detect as spam if the server name is not correctly set.

Here is an example of my vhost:

 # For default-pages
 <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/default
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/default>
                Options FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

# Doesn´t work, points to default (above code)
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName example.de
        DocumentRoot /var/www/example
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/example>
                Options FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

# All fine
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName example2.de
        DocumentRoot /var/www/example2
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/example2>
                Options FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>
1
  • That's why we have moderators. Und dein English is nicht "scheissig"! Nur "Imperfekt" – Fabby Nov 26 '14 at 0:40
1

According to Apache documentation:

If no ServerName is specified, then the server attempts to deduce the hostname by performing a reverse lookup on the IP address.

Reverse lookup: Look up an IP address to find the domain name for the IP address.

I guess that this is why example.de is served by your default VirtualHost, so try to add ServerName domain-i-got-but-not-active.de, and if this VirtualHost is the first defined:

it has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first VirtualHost.

0
<VirtualHost *:80>
    DocumentRoot /var/www/example
    DirectoryIndex index.php
    ServerName example.de 
    setEnv DOMAIN_NAME example.de 
   <Directory "/var/www/example">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Order allow,deny
         allow from all
         Require all granted
  </Directory>
  </VirtualHost>

try this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.