Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set up an nginx server to replace our current setup based on Apache. Our users have password protected directories (with directives in .htaccess files) which we need to keep protected in the new setup.

As far as I can see, nginx doesn't have a Directory directive, but only a Location directive, which refers to URIs instead of file system paths. This means that if a directory is reachable through more than one URL. I have to include them all in one or more Location directives. For example:, root: /home/user/public_html, root: /home/user/public_html/sub

If user protects (directory /home/user/public_html/sub/admin) I must make sure that both /admin in and /sub/admin in are protected with the same password file. I'd rather protect the directory itself, and not the URLs through which visitors can access its contents.

So, does nginx have any mechanism that allows to refer to file system paths in configuration files, like Apache's <Directory> blocks do - or maybe I'm just misreading nginx's documentation?

share|improve this question
I do not know of a direct replacement for the Directory attribute in Nginx. This is one of the biggest challenges in porting to Nginx is moving from a filesystem-focused view of configuration to a URI-focused configuration. Also, don't forget about regex. If everything is in /admin then a regex may work. – jeffatrackaid Oct 2 '12 at 18:39
Don't lay out the directory structure this way in the first place. Use separate directories for each virtual host, which are not nested within each other. – Michael Hampton Oct 26 '12 at 17:36

There's no such mechanism in nginx. I usually set different directories for different hosts:, root: /home/user/sites/, root: /home/user/sites/

which simplifies (nginx) configuration.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.