A
A
Andrew2014-01-09 01:38:50
Nginx
Andrew, 2014-01-09 01:38:50

Why does Location in location claim that its parameter is outside the parent folder?

server {
    listen 80;

    server_name localhost.dev;

    location /89262207055 {
        root /89262207055/;

        location /file {
            alias index.php?id=file&name=;
        }

        rewrite ^(.*).html$ index.php?id=block&block=$1;
    }
}

Above, at the level of the http directive, the root directory is registered. The folder itself 89262207055 opens through the server. But if you put this location /file there, then the server says at startup that location "/file" is outside location "/89262207055". The rewrite below also doesn't work, just no indication. Judging by the log, the server generally ignores it. Help me please. Examples of even your configs will do to compare.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MrJeos, 2014-01-10
@SkaN2412

location only tells the server which block of commands to execute, but does not change the environment. those. if you do it like this:

location /ololo {
root ololo1;
}

This will not lead to the $siteRoot/ololo/ololo1/ directory, but to $siteRoot/ololo1/.
This must be taken into account.
More.
This is if you want a normal replacement for what you need.
Something like this.

A
Aecktann, 2014-01-09
@Aecktann

First of all:
you can't:

location /a/ {
  location /b/ {
    bla;
  }
}

is that allowed:
location /a/ {
  location /a/b/ {
    bla;
  }
}
.
Secondly, the alias directive is not intended for rewrites. For rewrites, the rewrite directive is intended (suddenly! :) ). Using aliases and selections, you can redirect one static file to another, but not redirect a request to a dynamic one.
You need something like the following:
server {
    listen 80;

    server_name localhost.dev;

    rewrite ^(.*).html$ index.php?id=block&block=$1 last;

    location /89262207055 {
        root /89262207055/;
    }
    location /89262207055/file {
        rewrite ^ /index.php?id=file&name= last;
    }
    location /index.php {
        bla;
    }
}

Read the documentation, it's _very_ good.

Y
Yuriy Andamasov, 2014-01-09
@syncer

I suspect that the nested location is not relative to the main one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question