Hello, so I have been trying to block only a directory of a website for a few days now. I want to edit it and make it look like the site is telling the user you cannot view this page on this network; like DNS spoofing, but for a directory only.
I’m not very experienced with Nginx or Apache (in Ubuntu) so I’m not quite sure what my options are.
For an example, I want to block example.com/content/iwantthisblocked but I want everything else to be unblocked or “pass through.”
Can anyone help me with this? It would be very helpful as I do not want to spend the money on an expensive web filter.
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!
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.
Click below to sign up and get $200 of credit to try our products over 60 days!
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
As far as DNS goes, you won’t be able to block directory access using DNS. DNS simply routes the entries from the DNS provider (i.e. DigitalOcean or your domain registrar) to your web server. Once the request is routed, the web server handles the request and is responsible for how it’s handled (i.e. the response sent to the browser).
You can dig in to more routing options, of course, but for something as simple as blocking directory access, it’d be overkill since NGINX is capable of handling this for you.
Unless your router allows for the configuration of a destination or redirect, no. Some routers provide more advanced options, some not so much. It all boils down to what the firmware allows for.
Are you wanting to actually block access to the directory, or simply prevent visitors from being able to view the index listing of the directory?
If you want to simply prevent a directory listing, dropping an
index.phpfile in will prevent others from being able to view a listing of other files (but it will not prevent them from being able to access other files if they happen to guess file names i.e. random_filename.png, for example).
The other methods will require you to modify NGINX configuration, primarily the server block for the website. You’d need to login via SSH and pull up the website server block which should be located in:
sites-availableis symlinked to
sites-enabled, so you’d modify the file in the first and the second would be automatically updated.
To block access, you’d want to drop a
locationblock in to the file, which would look something like:
You’ll want to make sure you add that before other blocks, such as a
locationblock that allows PHP files to be accessed:
So, for example, it should look like this:
You can also block multiple directories using a single block, like so:
You would simply swap out
folder3with the paths to the folders you want to block.
That being said, the above also will not block access to files, only to the directory itself. So if someone guesses a random filename, they will still be able to access it.
example.com/content/iwantthisblocked will be denied.
example.com/content/iwantthisblocked/filename.html will not be denied.