🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 多个server_name中虚拟主机读取的优先级 ``` server { listen 80; server_name testserver1 jesont . tinywan . io; location{ root path / server1; } } server { listen 80; server_name testserver2 jesont . tinywan . io; location{ root path/server2; } } ``` > 优先级:优先读取最先读取的配置,server1、server2、server3 ## 多个location匹配的优先级 **匹配规则** `= `:进行普通字符精确匹配,也就是完全匹配 `^~`:表示普通字符匹配,使用前缀匹配 `~\~*`:表示执行一个正则匹配 **案例** ``` location = /code1/ { rewrite ^(.*)$ /code1/index.html break; } location ~ /code.* { rewrite ^(.*)$ /code3/index.html break; } location ^~ /code { rewrite ^(.*)$ /code2/index.html break; } ``` 访问:`127.0.0.1/code1` 优先级:组匹配:`code1`。`code1`注释掉,最匹配:`code3`。`code3`注释掉,最后匹配:`code2`