首页 > 其他 > 详细

nginx 精准匹配

时间:2015-06-02 15:29:27      阅读:255      评论:0      收藏:0      [点我收藏+]

精准匹配优先级最高

    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

 技术分享该图片我是将/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了

nginx 精准匹配

原文:http://linuxnewstar.blog.51cto.com/6967359/1657447

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!