最近我正在学习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;
}
答案 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 {
}