Apache alias; Map URL to a filesystem location

Apache alias is the method to use the filesystem other than under the document root.

Setting an alias directory with Apache means that when going to the specified URL path it will point to the set directory instead.

This is great when using block storage, as you can avoid putting the webserver onto the slower HDD.

The first step is to edit the Apache config files, Assuming your server has SSL:

sudo nano /etc/apache2/sites-enabled/000-default.conf

sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf

Include the alias, its format is:

Alias [URL path] [Diretory path]

Alias "/images" "/block_storage/images

Put this inside the <VirtualHost *:80> tag in the conf files.

The example above means that when I go to https://serverhostname.com/images it will be loading from /block-storage/images.

Next edit the main Apache configuration file:

sudo nano /etc/apache2/apache2.conf

Add the following in making sure to edit to the location to where your alias is set to

<Directory /block_storage/images/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Now make sure this location has the right permissions for www-data

sudo chown -R www-data:www-data /block_storage/images
sudo chmod -R g+rw /block_storage/images

All that’s left is to restart Apache

sudo systemctl restart apache2

And an Apache alias has been set up.