Access digital ocean volume using nginx alias

I would like to alias /home/mrneilypops/databank to /mnt/volume-fra1-01/databank I followed the guide here for nginx;

I added the alias to /etc/nginx/sites-available/default as per;

location /home/mrneilypops/databank/ {
                alias /mnt/volume-fra1-01/databank/;

This does not alias the volume databank file.

Any tips would be welcome…


I would like to access /home/mrneilypops/databank/ and show content of /mnt/volume-fra1-01/databank/ I am running Ghost blog on my site so I don’t know how I would access something like; http://droplet-ip/home/mrneilypops/databank/ in a browser…this would be the ideal solution.

Any suggestions welcome.

Wait a second. Do you want to when you or someone else type http://droplet-ip/home/mrneilypops/databank/ in browser it serves content from volume? Or you want when you go to /home/mrneilypops/databank/ in your console, SSH, it shows you content of it? If you want second, this tutorial will not work, as it works only if you want to serve it on Web, via nginx.

As per?

location /databank/ {
                alias /mnt/volume-fra1-01/databank/;

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

You are right with your configuration if you want to use http://droplet-ip/databank/. In your nginx server block you already added:

location /databank/ {
                alias /mnt/volume-fra1-01/databank/;

So that’s all. Make sure you restarted nginx after that. You can also test nginx configuration with:

  1. sudo nginx -t

It should ouput something in line of this:

Sample output of sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If this is OK, restart nginx:

  1. sudo systemctl restart nginx

Now there some important point: Accessing http://droplet-ip/databank will return 404 Not Found! Accessing via http://droplet-ip/databank/ (note the red slash) will work. To fix that remove last / in location /databank/. You will have now:

location /databank {
                alias /mnt/volume-fra1-01/databank/;

Restart nginx again and when you go to http://droplet-ip/databank it will return now 403 Forbidden. This is because you didn’t specified file to open. Go to /mnt/volume-fra-01/databank/ and create some html file (e.g. file called abc.html).

  1. nano abc.html

Write some html code in it:

nano abc.html
        <title>Hello World!</title>
        <p>Hello World!</p>

Save it and exit. Now go to http://droplet-ip/databank/abc.html from your browser and you should see Hello World! paragraph. If for some reason when you go to http://droplet-ip/databank you want to list all files, you can add autoindex on under nginx location block. This will show you all files you have in databank when you access http://droplet-ip/databank. For that your location block should look like this:

location /databank/ {
                alias /mnt/volume-fra1-01/databank/;
                autoindex on;

Restart your nginx once again, go to http://droplet-ip/databank/abc.html and you should see all files from databank directory on disk. Note that this is not something so recommended. Keep in mind that anybody will be able to see all your files in /mnt/volume-fra1-01/databank/.

If this is what you want, good luck, I hope it works for you :)

Read the guide again, note how location is a relative path, not an absolute one.