使用break会停止匹配下面的location,直接发起请求www.lansgg.com/c1.html,他会显示c2的内容;
使用last的话,会继续搜索下面是否有符合条件(符合重写后的/c2.html请求)的location。此时,/c2.html刚好与面location的条件对应上了,进入花括号{}里面的代码执行,这里会返回508。
server { listen 80 default_server; server_name www.lansgg.com lansgg.com; access_log logs/lansgg.access.log main; error_log logs/lansgg.error.log; root /opt/nginx/nginx/html/lansgg; index index.html; location /c1.html { rewrite /c1.html /c2.html last; } location /c2.html { return 508; } }
使用firebug 可以看到;
if 指令 可使用server, location 区域;
示例:当访问http://www.lansgg.com网址的时候跳转到www.Aries.com;
server { listen 80 default_server; server_name www.lansgg.com lansgg.com; access_log logs/lansgg.access.log main; error_log logs/lansgg.error.log; root /opt/nginx/nginx/html/lansgg; index index.html; if ($http_host = www.lansgg.com){ rewrite (.*) http://www.Aries.com; } }
return 指令 可使用server, location, if 区域
语法:return code
这个指令结束执行配置语句并为客户端返回状态代码,可以使用下列的值:204,400,402-406,408,410, 411, 413, 416与500-504。此外,非标准代码444将关闭连接并且不发送任何的头部。
rewrite_log 指令 可使用server, location, if 区域
启用时将在error log中记录notice 标记的重写日志。
set 指令 可使用server, location, if 区域
语法:set variable value
指令设置一个变量并为其赋值,其值可以是文本,变量和它们的组合。
你可以使用set定义一个新的变量,但是不能使用set设置$http_xxx头部变量的值。
uninitialized_variable_warn 指令 可使用 http, server, location, if 区域
语法:uninitialized_variable_warn on|off
默认值:uninitialized_variable_warn on
开启或关闭在未初始化变量中记录警告日志。
事实上,rewrite指令在配置文件加载时已经编译到内部代码中,在解释器产生请求时使用。
expires 指令 可 http, server, location 区域
语法: expires [time|epoch|max|off]
默认值: expires off
该指令可以控制HTTP应答中的“Expires”和“Cache-Control”的头标,(起到控制页面缓存的作用)。可以在time值中使用正数或负数。“Expires”头标的值将通过当前系统时间加上设定的 time 值来获得。
epoch 指定“Expires”的值为 1 January, 1970, 00:00:01 GMT。
max 指定“Expires”的值为 31 December 2037 23:59:59 GMT,“Cache-Control”的值为10年。
-1 指定“Expires”的值为 服务器当前时间 -1s,即永远过期
“Cache-Control”头标的值由指定的时间来决定: