首页 > 解决方案 > 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;
}

标签: nginx

解决方案


指令的值root是从周围的块继承的,如果它本身没有指定的话location。有关详细信息,请参阅此文档

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

在您的配置中,您为所有 URI 指定根,但以、或/home/ubuntu/demo/web_file/production开头的那些除外。/vendors/srcbuild


您不需要index在每个位置重复相同的语句,因为它也是从周围的块继承的,如果它location本身没有指定的话。有关详细信息,请参阅此文档

例如:

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 {
}

推荐阅读