Nginx路由配置

时间:2018-10-22 09:14:47

标签: nginx

最近我正在学习nginx,我不理解下面的路由配置,有人可以解释吗?谢谢!

root /home/ubuntu/demo/web_file;
location / {
    root /home/ubuntu/demo/web_file/production;
    index  index.html index.htm;
}
location /vendors {
    index  index.html index.htm;
}
location /src {
    index  index.html index.htm;
}
location /build {
    index  index.html index.htm;
}

1 个答案:

答案 0 :(得分:1)

如果root本身未指定,则location指令的值将从周围的块继承。有关详细信息,请参见this document

location /块实际上是默认位置,并且与任何其他location块不匹配的URI匹配。

在您的配置中,您将所有URI(除了以/home/ubuntu/demo/web_file/production/vendors/src开头的URI的根都指定为build


您无需在每个位置重复相同的index语句,因为如果未在location本身中指定,它也将从周围的块中继承。有关详细信息,请参见this document

例如:

root /home/ubuntu/demo/web_file;
index  index.html index.htm;
location / {
    root /home/ubuntu/demo/web_file/production;
}
location /vendors {
}
location /src {
}
location /build {
}