Nginx, Disable access to .htaccess file, and other hidden files
Global Restrictions to files starting with “dot” (.) would be like this:
# Deny all attempts to access hidden files
# such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
}
This of course will forbid access to all kind of files starting with dot.
One extra improvement would be to allow certain folder starting with dot, not to be denied.
You can do that again with the location directive, in this case for .well-known
# Allow access to the ACME Challenge for Let's Encrypt
location ~ /\.well-known\/acme-challenge {
allow all;
}
# Deny all attempts to access hidden files
# such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
}
…
tags: & category: -