3

How can I protect all files and other directorys in a specific directory (-> recursively) in Nginx so they can't be accessed from the web?

1 Answers1

4

You can deny access to locations with a specific prefix. nginx resolves locations to directory paths by using the value of the root or alias directive.

The prefix location with the ^~ modifier takes highest precedence and can therefore be used to deny access to specific parts of the hierarchy:

location ^~ /secret { deny all; }
location ^~ /secret { return 404; }

The above will return a 403 or 404 error response to any URI beginning with /secret.

See this document for details.

Richard Smith
  • 12,834
  • 2
  • 21
  • 29