精准匹配优先级最高

    server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;              #相对路径,也就是nginx的安装路径

            index  index.html index.htm;

        }

        location = / {

             root /usr/local/w/;

             index index.html;

        }

这个如果在浏览器里访问http://127.0.0.1/的话仍然会匹配到/usr/local/w/,匹配到这个目录后因为是精确匹配只对当前目录生效,就不再往下匹配,然后跳到默认的/匹配,匹配到/usr/local/nginx/html/index.html

 wKiom1VtM0iBW7SZAADhFLGq5n0142.jpg该图片我是将/usr/local/w/index.html更改为index.htm,而index.htm在/usr/local/nginx/html里面是没有的,所以出现上图的faild,更改过来后,signal process started。所以一般的精确匹配是不直接用= /目录,而是=/主页

 server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;              #相对路径,也就是nginx的安装路径

            index  index.html index.htm;

        }

        location = /index.html{

             root /usr/local/w/;

             index index.html;

        }


这样就能实现访问/usr/local/w/index.html了