zoukankan      html  css  js  c++  java
  • nginx 的location的匹配顺序

    匹配规则

    匹配顺序

    示例

    [root@python vhast]# cat test.conf 
    server {
            server_name haha.com;
            #listen 8080;
    	rewrite_log on;
            error_page 404 /403.html;
            #return 405;
            location /{
                    #return 404 "find nothing!
    ";
            }
    	root html/;
    	location /first {
    		rewrite /first(.*) /second$1 last;
    		return 200 1first!
    ';
    		}
    	location /second {
    		#rewrite /second(.*) /third$1 break;
    		rewrite /second(.*) /third$1 last;
    		return 200 'second!
    ';
    		}
    	location /third {
    		return 200 'third!
    ';
    	}
    	location /redirect1 {
    		rewrite /redirect1(.*) $1 permanent;
    	}
    	location /redirect2 {
    		rewrite /redirect2(.*) $1 redirect;
    	}
    	location /redirect3 {
    		rewrite /redirect3(.*) http://haha.com:$1;
    	}
    	location /redirect4 {
    		rewrite /redirect4(.*) http://haha.com:$1 permanent;
    	}
    	location ~ /Test1/$ {
    		return 200 'first regular expressions match! 
    ';
    	}
    	location ~* /Test1/(w+)$ {
    		return 200 'longest regular expressions match! 
    ';
    	}
    	location ^~ /Test1/ {#禁止正则匹配
    		return 200 'stop regular expressions match! 
    ';
    	}
    	location /Test1/Test2 {
    		return 200 'longest prefix string match! 
    ';
    	}
    	location /Test1 {
    		return 200 'prefix string match! 
    ';
    	}		
    	location = /Test1 {  #精确匹配
    	return 200 'exact match!
    ';
    	}	
    }
    

      测试

    [root@python vhast]# curl http://haha.com/Test1
    exact match!
    [root@python vhast]# curl http://haha.com/Test1/
    stop regular expressions match! 
    [root@python vhast]# curl http://haha.com/Test1/Test2
    longest regular expressions match! 
    [root@python vhast]# curl http://haha.com/Test1/Test2/
    longest prefix string match! 
    [root@python vhast]# curl http://haha.com/test1/Test2  #没有匹的话会记住匹配最长的那个
    longest regular expressions match! 
    

      

    草都可以从石头缝隙中长出来更可况你呢
  • 相关阅读:
    iOS- 优化与封装 APP音效的播放
    iOS- iPhone App 如何运营?
    iOS- 封装单例宏
    iOS- 详解文本属性Attributes
    iOS- 如何将应用集成发短信、发邮件、打电话
    iOS- <项目笔记> UIApplication常见属性与方法总结
    iOS- <项目笔记>iOS6 & iOS7屏幕图片适配
    iOS- <项目笔记>项目配置常见文件
    iOS- <项目笔记>UI控件常见属性总结
    iOS- UIPickerView餐厅点餐系统
  • 原文地址:https://www.cnblogs.com/rdchenxi/p/11153194.html
Copyright © 2011-2022 走看看