By neilhoughton
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…
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Read the guide again, note how location is a relative path, not an absolute one.
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:
- sudo nginx -t
It should ouput something in line of this:
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:
- 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).
- nano abc.html
Write some html code in it:
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
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 :)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.