Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I wrote this to prevent the directory "download" to be accessed but from the IP 1.2.3.4.

location ~ /folder/download {
    allow 1.2.3.4;
    deny all;
    return 403;
}

However, the directory "folder" is being blocked as well and I did not wanted this.

What am I doing wrong?

UPDATE:

Here it goes all the real config:

server {
    server_name www.domain.com;
    rewrite ^ $scheme://domain.com$request_uri? permanent;
}

server {
    server_name atpc.info;

    access_log /var/log/nginx/atpc.info.access;
    error_log /var/log/nginx/atpc.info.error;

    root /var/www/atpc.info;

    location ^~ folder/download {
            allow 1.2.3.4;
            deny all;
    }

    location ^~ folder/includes {
            allow 1.2.3.4;
            deny all;
    }

    location ^~ folder/mythings {
            allow 1.2.3.4;
            deny all;
    }

    location ^~ folder/functions {
            allow 1.2.3.4;
            deny all;
    }

    location / { index index.htm index.php; }

    location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
    }

    location = /favicon.ico {
            return 204;
            access_log off;
            log_not_found off;
    }

    location = /robots.txt { allow all; log_not_found off; access_log off; }
    location ~ /\. { deny all; access_log off; log_not_found off; }
}

Thanks.

share|improve this question
    
Your config looks fine. Is there any other location related to folder? Could you please post the full config? –  quanta Oct 14 '11 at 2:02
    
I updated the question. –  Roger Oct 14 '11 at 17:48
add comment

1 Answer

up vote 1 down vote accepted

You probably want location ^~ instead of location ~, as the former is a prefix match that doesn't allow regex overrides, and the latter is a regex location. Also, remove the return 403; The allow and deny directives are sufficient for your application, and the return will always be evaluated, which means everyone will get a 403.

share|improve this answer
    
Sorry, but it's not working... –  Roger Oct 14 '11 at 17:44
    
I updated the question. –  Roger Oct 14 '11 at 17:48
1  
/f/f is a prefix of /f/form.js, so location ^~ /f/f blocks it. What about that isn't working? If all those are supposed to be dirs, then maybe you need to add slashes at the end of each one. location ^~ /f/f/ { ... } –  kolbyjack Oct 14 '11 at 18:02
add comment

Your Answer

 
discard

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.