Nginx forbidden

Nginx deny access to certain directory or folder

I use Nginx for 8 years now (2021) and I am happy with it. If you need to hide or restrict access a folder or directory publicly you can use the sample code below.

location ~ /(app|system|logs) {
   deny all;
   return 404; # 403 (forbidden)
}

Note that you need to change the parameters above with your directory or folder that you want to hide or restrict. You can display a 404 error message or 403 message. I prefer displaying the 404 directory to confuse the user that such directory does not exist to prevent or discourage them from going or scraping your website.

Thanks for reading. Nginx rocks…