Question

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

Posted August 30, 2016 11.7k views
DebianLEMPBlock Storage

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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

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

Hi All,
We have followed this documentation, unfortunately we are not able to connect volume that we have created from Snapshot from Droplet.

When we tried the following command which is giving following result.
ls -lsh
64K drwxrwsr-x 2 www-data www-data 60K Apr 1 04:25 payum
0 lrwxrwxrwx 1 www-data www-data 27 Jun 3 2018 public -> /mnt/volumes-ams3/public/

We would like to connect that public folder to the volume that we have created recently. mnt/volumes-ams3 was created to used in different Droplet.

How can we change it to point to our volume ?

Appreciate your help.

Submit an Answer