Question

Blocking a directory of a website via DNS

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.

Thanks!

Show comments

Submit an answer


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!

Sign In or Sign Up to Answer

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.

Accepted Answer

@AireServ

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.

@AireServ

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.

I am not sure what the intent is but you could change the permissions on the folder so it’s not accessible to Apache and Apache will generate a 403 forbidden message to the end user.

chmod 000 /path/to/iwanthisblocked

Change mode to 644 if you want it to be accessible.

chmod 755 /path/to/iwanthisblocked

You can customize the 403 message. https://httpd.apache.org/docs/2.4/custom-error.html has details.

Gaurav

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.