I would like to know how to let people access files with a direct link on my server but restrict them from accessing all directories?
Exemple: I want them to see www.site1.com/usa/newyork/1.html I don’t want people to be able to access either www.site1.com/usa/ nor www.site1.com/usa/newyork
I have tried; command: sudo nano /etc/nginx/sites-available/site1.com … location ~ /(usa) { deny all; return 404; } …
But after that I can’t access the rest myself… even with a direct link: www.site1.com/usa/newyork/1.html
Thank you for your help,
Octav
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!
Problem is solved! <br> <br>So, by default Nginx has an option called autoindex set to off! <br>This command line: autoindex on; will activate the ability to see your directories (to everyone). <br> <br>In my case, I wanted to restricted people from wondering around my server just by typing the www.exemple.com/test1/test2 and be able to see what is inside it without specifying the direct link to it example: www.exemple.com/test1/test2/image1.png <br> <br>There is a command also that is important that sets a priority of file searching; <br> <br>location / { <br> try_files $uri $uri/ =404; <br>} <br> <br>This command means it will try to access the file 1st then the folder then give you an error 404 if nothing works. <br>More info: http://stackoverflow.com/questions/17798457/how-can-i-make-this-try-files-directive-work <br> <br> <br> <br> <br>
Also, my configuration has index.html, index.php, index.htm set as default. So if you don’t want people to access other folders without typing in the whole path change either you default settings or change the name of your files ex: index1.html …
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.