1.12 nginx的rewrite配置-if
1.13 rewrite中的break和last.
新建一个虚拟主机 vim www.1.com.conf
更改配置文件error_log级别
1.html 里面为11111 2.html 里面为22222 3.html 里面为33333
cutl测试打开1html,转到3.html 因为虚拟要机中配置1 转2 2转3
break
last
当使用location 不加break 和 last 时
加载配置文件测试
b之后 在去匹配根的location 发现不匹配就返回结果
要在location 里面
把break 改为last
同一个location 下last 后面的不执行
之后会匹配第二个location /2.html 2跳转到a ,但a不存在
总结:
break 在本location 和其它的location也不会执行
last 在本location 不执行, 匹配下一个location
如果两个 都 不在location 下使用,效果一样
1.14 nginx中的return用法
用法一. 直接返回状态码
用法二,返回自符串
用法三,返回url
返回跳转到连接信息
1.15 rewrite规则语法
方法一:
方法二:
加-L 跟着后面一点一点访问
-L -I 可以看到过程,5次后就返回结果
最终正确定法:
if ($request_uri !~ ‘^/bbs/’)
{
rewrite /(.*) /bbs/$1 redirect;
}
access_log /tmp/2.log;