Nginx location ~ /\.ht

nginx

What is the meaning of the following location block in Nginx?

location ~ /\.ht {
    deny all;
}

I ask since I have a small WordPress site and I removed this block from its configuration and restarted the server but the site kept working fine, seemingly.

Best Answer

location ~ /\.ht {
    deny all;
}

This directive tells the webserver to deny all incoming requests for any files starting with .ht in the root directory (/).

The tilde ~ tells nginx to use regular expressions.

Thus, files like .htaccess, .htpasswd, etc, will not be served.

Note: The backslash (\) before the dot, is just to escape the dot (the dot that comes before htaccess, htpassword, etc.

Related Question