0

I want to set path like this:

    location /board/1 {
        alias /home/front/;
        break;
    }

    location /board/2 {
        alias /home/front/;
        break;
    }

    location /board/{ANY_NUMBER 3..} {
        alias /home/front/;
        break;
    }

So I write like this:

location ^~ /board/ {
    alias /home/front/;
    break;
}

Then I go to /board/1

nginx access to /home/front/1

I want to access to /home/front

When I set like this:

location /board/1 {
    alias /home/front/;
    break;
}

nginx access to /home/front successfully

Can someone explain what's going on.

nkhcode
  • 87
  • 1
  • 8

1 Answers1

0

By using the alias directive nginx basically replaces the part of your location path (in this case /board/1 or /board) with the path specified by the alias directive (/home/front/). Therefore if you use the number in the location path, it will be replaced, but it will be kept if it’s not in the location path.

You probably want to use a regex location instead:

location ~* ^/board/[0-9]+/ {
    alias /home/front/;
}
rauberdaniel
  • 1,017
  • 9
  • 22
  • nginx access to `/home/front/board/1` like this. But I need to access to `/home/front/` because index.html file is in /home/front – nkhcode Mar 12 '21 at 13:16