0

In Ubuntu 2016.04's default Apache2, I tried to add a virtual host with an alias:

sudo mkdir /var/www/simplesamlphp
echo "Hello" > /var/www/simplesamlphp/index.html (as root)
sudo chown -R www-data:www-data /var/www/simplesamlphp
sudo chmod -R 755 /var/www

Second, I created /etc/apache2/sites-available/simplesamlphp.conf:

<VirtualHost *>
    ServerName simplesamlphp
    DocumentRoot /var/www/simplesamlphp

    SetEnv SIMPLESAMLPHP_CONFIG_DIR /var/simplesamlphp/config

    Alias /simplesaml /var/simplesamlphp/www

    <Directory /var/simplesamlphp/www>
        <IfModule !mod_authz_core.c>
        # For Apache 2.2:
        Order allow,deny
        Allow from all
        </IfModule>
        <IfModule mod_authz_core.c>
        # For Apache 2.4:
        Require all granted
        </IfModule>
    </Directory>
</VirtualHost>

Third, I added this line to /etc/hosts:

127.0.0.1       simplesamlphp

Fourth, I ran:

sudo a2enmod rewrite
sudo a2ensite simplesamlphp.conf
sudo service apache2 restart

PROBLEM: Accessing http://simplesamlphp/simplesaml gives The requested URL /simplesaml was not found on this server and the following appears in /var/log/apache2/error.log:

AH00128: File does not exist: /var/www/html/simplesaml

What did I do wrong?
By the way, I am following these instructions. Actually, I am not sure why a DocumentRoot is needed despite all web content being in /var/simplesamlphp/www.

Nicolas Raoul
  • 11,921

1 Answers1

2

Note to readers: Please read Henning Kockerbeck's comments. Apache 2.4 virtual hosts functionality is well described in the official guide. The following answer is out of date.

The best explanation why the procedure works is the following (from the documentation):

When a request arrives, the server will find the best (most specific) matching argument based on the IP address and port used by the request. If there is more than one virtual host containing this best-match address and port combination, Apache will further compare the ServerName and ServerAlias directives to the server name present in the request.


If you haven't disabled the default site 000-default you now have two <VirtualHost *> declarations, and the default one is not name-based. Apache cannot distinguish between them, and in order to solve the ambiguity it will simply ignore the second one. You can proceed in three different ways:
  • You may choose to disable the default site, or
  • You may choose to make your new virtual host listen on a different port, or
  • You may choose to convert the default site into a name-based virtual host by editing 000-default.conf, uncommenting the ServerName directive and assigning a different name to it.
AlexP
  • 10,435