Categories: Development

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.

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago