I have a home webserver running nginx and was wondering how I can deny access to two files that are in multiple directories but still allow access to everything else
multiple directorys inside the main /servers directory contain file1.txt and file2.txt
I need to make a rule to block access to these two files in any directory inside /servers but allow access to all other files inside /servers
Hi
If you use Apache, you’re all done, because of the .htaccess file already there. If you’re using Nginx, you need to edit your Nginx config to make your website work, because Nginx doesn’t understand .htaccess rules”.
Using Apache and Nginx at the same time is quite uncommon.
This will block all files anywhere that contain that name and extension ( .htaccess )
<FilesMatch "file1.txt|file2.txt">
Order Deny,Allow
Deny From all
</FilesMatch>
make sure you don’t have a space between|
besides, it would be desirable to have this as well
# Disable Directory Listings in this Directory and Subdirectories
# This will hide the files from the public unless they know direct URLs
Options -Indexes
, I got this error nginx: [emerg] using regex “console.txt|bans.txt|ladderlog.txt|reports.txt|login_error.txt” requires PCRE library in /usr/local/nginx/conf/nginx.conf:77
it looks like I need to get the pcre library and recompile nginx