8

Somehow my Virtual host files are not working straight I can't tell why - I bet it's just a mailfunction in my good-morning brain :p

Right now I got TWO sites enabled via a symbolic link to sites available in /etc/apache2/ directory like :

0 Nov 21 12:24 000-default -> ../sites-available/default
0 Nov 21 14:52 001-site -> ../sites-available/site

my VHosts files look like :

DEFAULT

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName (the IP Address from my Server)
        ServerAlias (the 2nd IP Address from my Server)
        DocumentRoot /var/www/default
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/default>
                Options FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

SITE

<VirtualHost *:80>
    ServerAdmin myname@example.de
    DocumentRoot /var/www/site/
    ServerName jobbörse-köln.de
    ServerAlias www.example.de ww.example.de w.example.de

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/site>
            Options FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/site-error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/site-access.log combined
</VirtualHost>

Somehow when I go on "example.de" I get to the DEFAULT Directory instead of the SITE Directory. Even the log files :

site-error.log
site-access.log

stay on 0 bytes ... what am I doing wrong ? I bet it's something dumb and easy ...

Kris
  • 567
  • 3
  • 11
  • 25
  • where are your vhost.conf files located? what is that you see when you access your site? What about your httpd.conf? – Keerthivasan Nov 22 '13 at 14:42
  • My Vhost Files are located in : /etc/apache2/sites-available and they get linked in /etc/apache2/sites-enabled my apache2.conf is located in /etc/apache2/ When I go on www.example.de I get the index.php from /var/www/default/ instead of /var/www/site/ – Kris Nov 22 '13 at 14:50

1 Answers1

9

You are using the default 80 port for both the virtual host entry. So I hope you are using NameVirtualHost *:80 as configuration.

in the configuration you shared VirtualHost are getting overlaped on port 80, so the first has precedence.

  • I can't listen more as on VHost on port 80 ? – Kris Nov 22 '13 at 23:42
  • 2
    @y_nk I am guessing you are facing the issue while using same IP+PORT combination with two or more VirtualHost like above (*:80) where * is for all IPs(it may vary for definite IP like 209.207.228.12:80). If yes then you have to tell the Apache that *:80 is being used by two different VirtualHost directives. Hence you need to add NameVirtualHost *:80(For above case) before adding these two directives. After then ServerAlias will pick your configuration accordingly. Hope it will solve your problem. – Mandip Mankotia Apr 15 '14 at 15:45
  • 1
    actually after few hours hanging in stacknetwork i found the proper answer : http://stackoverflow.com/a/19521307/335243 it looks weird but it works :) thanks @MandipMankotia – y_nk Apr 16 '14 at 11:48
  • This answer is somehow misleading. Also note that the `NameVirtualHost` directive is deprecated since years. – Valerio Bozz May 15 '20 at 12:24