berricks
By:
berricks

How do I access the space on an attached volume from my webroot?

August 30, 2016 3.7k views
LEMP Block Storage Debian

I have some large image directories for a webcam site. The directories are in this path /var/www/boulderflatironcam.com/public_html/ on the server. The web root was laid out on the droplet's 40GB disk and I was expecting the block storage to just extend this disk. I started rsyncing files from another server and filled up the main disk. It looks like it comes up as an attached storage device. Do I need to move the whole web directory to the new storage or is there a way to put just certain directories on the block storage? Or, is there a way to just have the block storage extend the basic server disk?

1 comment
  • I'm running nginx on the droplet. I was able to create the directories on the storage volume so now it seems like I just need a way for the website to access these directories. Probably similar to the apache answer below?

2 Answers
asb MOD August 30, 2016
Accepted Answer

It's is also possible to do this using Nginx's simularly named alias directive. Again, let's say your storage volume is mounted at /mnt/volume-nyc1-01 and that you want http://example.com/images to be served from the volume. First, you would need to create a directory on the volume that you can give ownership to the www-data user. E.g:

  • mkdir /mnt/volume-nyc1-01/images
  • sudo chown -R www-data:www-data /mnt/volume-nyc1-01/images

Then you'll need to edit your Nginx's configuration. By default, that is found at /etc/nginx/sites-enabled/default. Now add an alias directive pointing /images to /mnt/volume-nyc1-01/images:

        location /images/ {
                alias /mnt/volume-nyc1-01/images/;
        }

Finally, restart Apache for the changes to take effect:

  • sudo service nginx restart

You can use Apache's Alias directive to point a path to a specific directory outside of your web root. For example, let's say your storage volume is mounted at /mnt/volume-nyc1-01 and that you want http://example.com/images to be served from the volume. First, you would need to create a directory on the volume that you can give ownership to the www-data user. E.g:

  • mkdir /mnt/volume-nyc1-01/images
  • sudo chown -R www-data:www-data /mnt/volume-nyc1-01/images

Then you'll need to edit your Apache configuration. By default, that is found at /etc/apache2/sites-enabled/000-default.conf. Now add an Alias directive pointing /images to /mnt/volume-nyc1-01/images:

        Alias /images /mnt/volume-nyc1-01/images
        <Directory /mnt/volume-nyc1-01/images>
                Require all granted
        </Directory>

Finally, restart Apache for the changes to take effect:

  • sudo service apache2 restart

You can find out more details about how Block Storage volumes work in this tutorial: https://www.digitalocean.com/community/tutorials/how-to-use-block-storage-on-digitalocean

DigitalOcean's Block Storage allows you to create and attach additional storage volumes to your DigitalOcean Droplets. Volumes are an independent resource that can easily be moved from one Droplet to another within the same datacenter. Attached volumes function like locally connected storage drives, allowing you to manage your storage with familiar tools and techniques.
  • This is excellent but I'm using nginx. Would it have similar steps?

  • I followed the above steps for apache configuration and it didn't work. Does anyone know if there other steps that I might be missing? It just keeps saying page or file not found, 404 error. I've tried changing permissions for the folder and nothing. thought anyone? :/

Have another answer? Share your knowledge.