Apache2 virtual host missing Document Root

1.5k views Asked by At

thank you in advance.

I just following a tutorial from digitalocean : https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts . I completed all instruction but when I start to test the configuration and add an A Record from my parking domain, let say example.com and my digitalocean vps address is 192.168.10.2. In this schenario I add these 3 virtual host with 3 different DocumentRoot:

  1. /var/www/domainone.example.com/index.html
  2. /var/www/domaintwo.example.com/index.html
  3. /var/www/domainthree.example.com/index.html

Then in my parking domain I add 3 different A record as below :

  1. name : domainone.example.com address : 192.168.10.2
  2. name : domaintwo.example.com address : 192.168.10.2
  3. name : domainthree.example.com address : 192.168.10.2

When I execute, it happens as follow :

  1. URL domainone.example.com goes to /var/www/domainone.example.com/index.html
  2. URL domaintwo.example.com goes to /var/www/domaintwo.example.com/index.html
  3. but this URL domainthree.example.com goes to /var/www/domaintwo.example.com/index.html

I am sure that I wrote a correct documentRoot at /etc/apache2/sites-available/(for each domain).config and restart the apache2 service

Thank you again

Edit

  1. This is for /etc/apache2/sites-available/domaintwo.example.com.conf

    <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
    
        ServerAdmin localhost@admin
        DocumentRoot /var/www/domaintwo.example.com/public
        ServerName domaintwo.example.com
        ServerAlias www.domaintwo.example.com
    
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        SSLEngine on
    

    SSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key

  2. This is for /etc/apache2/sites-available/domainthree.example.com.conf

        <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
    
        ServerAdmin localhost@admin
        DocumentRoot /var/www/domainthree.example.com/public
        ServerName domainthree.example.com
        ServerAlias www.domainthree.example.com
    
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        </VirtualHost>
    
1

There are 1 answers

1
Roman On

It's a SSL issue IMO. Domain 2 is alphabetically sorted higher then 3 (priority). Apache executes domaintwo as default via HTTPS (SSL). So the VH for domain 3 is wrong or not enabled for both protocols. I'm guessing more or less. Hope it helps.