How does 'locate' work?

Maxim Dounin mdounin at
Thu Oct 22 21:55:50 MSD 2009


On Thu, Oct 22, 2009 at 01:05:41PM -0400, GAZ082 wrote:

> Awesome article. Been trying to tune it up a little, and now i'm getting a 403 in the directory documents, here is my full config:

Is 403 differs from what you expect?

403 is perfectly valid code, and it's returned by nginx in 
serveral situations, including the following you may want to 

1. auth_basic specified in config, but specified 
auth_basic_user_file doesn't exists

2. directory index requestd but not allowed (i.e. no index file in 
directory, and autoindex not enabled)

Both should log reason in error_log at error level.

> server {
>     listen       80;
>     server_name;
>     #rewrite ^/(.*)$1 permanent;
>     access_log /var/www/;
>     error_log /var/www/;
>     location / {
>         root   /var/www/;

It's probably a good idea to move root directive to server{} 
level.  This will save you some typing in each location.

>         index  index.html index.htm index.php;
>     }
>     location /documents { 

Note that this matches anything that starts from "/documents", 
including /documents.html and so on.  Use "/documents/" to match 
directory only.

>         root /var/www/;
>         auth_basic            "Access restricted.";
>         auth_basic_user_file   /var/www/;
>     }

Otherwise looks perfectly correct.  Note well that it has no index 
directive, and therefore default index.html will be used.

If you expect this should have the same indices as in "location /", 
you probably have to move index directive from "location /" to 
server{} level as well.

>     location ~ .php$ {

So your .php files in /documents/ won't be protected.  See example 
4 (as far as I remember numbering) in my previous message.

Maxim Dounin

More information about the nginx mailing list