location{} hassles:(

Maxim Dounin mdounin at mdounin.ru
Thu Dec 5 15:03:46 UTC 2013


On Thu, Dec 05, 2013 at 01:10:53AM +0000, Matthew Ngaha wrote:

> Hey all I can't seem to get the hang of how to use/write location
> blocks. I have mailed the list before and I do understand how it works
> but what I've tried fails.
> I have tried a few things and in both cases i don't think what i'm
> doing is making a difference. Here they are:
>                               http://bpaste.net/show/YXFXLuJ1Uc1UFQDc8ctn/
> The 1st test was to put location {} nested into the main location {}
> that was already in nginx.conf. I put the "deny  all;" just to see if
> it would find or ignore/ my new location {} but the nested location
> test directory/file isn't denying access.
> The 2nd  location {} test is below the main one. In the installed
> nginx folder it uses html/ as the root, i tried to create a test
> "delete" folder as an alternative location to the html root folder but
> i can't seem to get it right. My browser returns a "404 Not Found"
> when i try to access files in localhost/delete.
> In both cases my added locations {} are being ignored. Any ideas what i can do?

Try looking into error log and full config, and make sure you've 
reloaded configuration after changing it.

With the config you've posted, i.e.:

        location / {
            root   html;
            index  index.html index.htm;

            location /test/file.html {
                deny all;

	location /delete {
            root   delete;

and assuming there are no other locations defined, expected 
results are:

request to /foo maps to file <prefix>/html/foo
request to /test/files.html returns 403
request to /delete/foo maps to file <prefix>/delete/delete/foo

See here for documentation:


Maxim Dounin

More information about the nginx mailing list