Search code examples
apachetomcatvirtualhostmod-proxy

Apache virtualhosts not working for subdomain


I am having trouble with setting up a apache server on ubuntu.

I need to have the main domain loading just a website, but a subdomain loading a tomcat server. To acheive this I follwed the instructions here: https://sites.google.com/a/ci2s.com.ar/wiki/technics/how-to-run-apache-httpd-and-tomcat-on-port-80-using-mod-proxy

This didn't work, both the main and the subdomain point to the same folder. I found on serveral answers here that I shoudl include the line NameVirtualHost *:80

However when I restart the apache server i get the follwing warning:

 AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/ginl.hodzelmanstechnology.nl.conf:1

Can anybody help me with this?

Some output to help troubleshoot:

ls /etc/apache2/sites-enabled/
ginl.hodzelmanstechnology.nl.conf  kantoor.ginl.hodzelmanstechnology.nl.conf

cat /etc/apache2/sites-available/kantoor.ginl.hodzelmanstechnology.nl.conf
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin 1353691hodzelmans@zuyd.nl
    ServerName kantoor.ginl.hodzelmanstechnology.nl/
    DocumentRoot /var/www/kantoor.ginl.hodzelmanstechnology.nl/

    ErrorLog /var/log/apache2/kantoor.ginl.hodzelmanstechnology.nl-error.log

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

    CustomLog /var/log/apache2/kantoor.ginl.hodzelmanstechnology.nl-access.log combined
    ServerSignature Off

    # lets indicate the proxy what path do we want
    # to forward to tomcat
    ProxyPass / http://localhost:8080/

    <Directory /var/www/kantoor.ginl.hodzelmanstechnology.nl/>
            Options FollowSymLinks
            AllowOverride All
            Options -MultiViews
    </Directory>
</VirtualHost>

cat /etc/apache2/sites-available/ginl.hodzelmanstechnology.nl.conf
NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin 1353691hodzelmans@zuyd.nl
    ServerName http://ginl.hodzelmanstechnology.nl/
    DocumentRoot /var/www/ginl.hodzelmanstechnology.nl/

    ErrorLog /var/log/apache2/ginl.hodzelmanstechnology.nl-error.log

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

    CustomLog /var/log/apache2/ginl.hodzelmanstechnology.nl-access.log combined
    ServerSignature Off

    <Directory /var/www/ginl.hodzelmanstechnology.nl/>
            Options FollowSymLinks
            AllowOverride All
            Options -MultiViews
    </Directory>
</VirtualHost>

apache2 -v
Server version: Apache/2.4.7 (Ubuntu)
Server built:   Mar 10 2015 13:05:59

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty

Solution

  • You need to define your subdomain in the "VirtualHost" element of your config file, so the server may distinguish between different hosts:

    <VirtualHost kantoor.ginl.hodzelmanstechnology.nl:80> 
     ...
    </VirtualHost>