-2

I have 2 entires in the 000-default file. One of them is about a subdomain and the another is about everything else. The problem is that just one works, what is the first in the file. So if i write first the subdomain entry that works if the another then that.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                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

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

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

    <Location /svn>
    DAV svn
    SVNParentPath /home/svn
    AuthType Basic
    AuthName "Your repository name"
    AuthUserFile /etc/subversion/passwd
    Require valid-user
    SVNPathAuthz On
#   SVNAdvertiseV2Protocol Off
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName  sub.domain.com
    ServerAlias sub.domain.com

    DocumentRoot /var/www/sub.domain
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/sub.domain/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        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

</VirtualHost>

RewriteEngine On
Gábor Varga
  • 101
  • 1

2 Answers2

0

Try using NameVirtualHost *:80 on the top of the virtual host config.

chetangb
  • 145
  • 6
  • I set and after it I restarted the Apache ( service apache2 restart ) and I got a message: "NameVirtualHost *:80 has no VirtualHosts". – Gábor Varga Jun 17 '15 at 15:06
  • http://httpd.apache.org/docs/2.4/vhosts/name-based.html#defaultvhost . You need to set Servername instead of * , then on add sub with ServerName followed by ServerAlias ServerName defaultnameof the server ... .. ServerAdmin webmaster@localhost ServerName sub.domain.com ServerAlias sub.domain.com – chetangb Jun 17 '15 at 15:23
  • I didn't know if you are using 2.2 or 2.4 but for 2.4 it works if you have a default hostname if nothing is applicable. – chetangb Jun 17 '15 at 15:25
  • And what is the default hostname? I have an ip address, the ip address should point to the /var/www directory but the subdomain (at the same time) should point to the /var/www/sub.domain. I put 2 entries as you can see above, its the file (named default). And! This exactly this is working on ubuntu but now its a debian. Would be the distribution matter? And if yes how/what? – Gábor Varga Jun 17 '15 at 16:23
0

Both are working for me correctly ServerAdmin webmaster@localhost ServerName puppetmaster.matrix.nx DocumentRoot /var/www/html Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all

ServerAdmin webmaster@localhost ServerName puppet.matrix.nx ServerAlias puppet.matrix.nx

DocumentRoot /var/www/sub.domain
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/sub.domain/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

[root@puppetmaster conf.d]# GET http://puppetmaster.matrix.nx/ test page1

[root@puppetmaster conf.d]# GET http://puppet.matrix.nx/ test page2

chetangb
  • 145
  • 6
  • For me too. The problem is that, when I put the both to a config file then, at the same time just the first is working. ( And I dont have more domains, just a subdomain and an ip address. ) – Gábor Varga Jun 17 '15 at 16:25
  • Apache will basically ignore the second as the first one is matching , as per the vhost doc in these type of case it will always use the first one in the file. If you don't have more than one domain then you need to specify the ip and vhostname instead of "*" `` `` , this should work for you as it works for me with single sub-domain and an IP. Hope this helps!.. :) – chetangb Jun 17 '15 at 16:52
  • I really dont know why, but exactly this config works on a server what is Ubuntu 13.10 and Apache 2.4.9. I think, ill replace the debian to ubuntu. Thats all, Thank you! – Gábor Varga Jun 17 '15 at 18:28