前提true.html文件不存在
配置
location ~ /error.html {
rewrite ^/(.*) /true.html break;
}
location ~ /true.html {
if ( !-e $request_filename ){
return 508;
}
}
[root@A ]# wget -SO /dev/null http:///error.html
--2014-06-30 00:17:23-- http:///error.html
Resolving ... 192.168.1.200
Connecting to |192.168.1.200|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 404 Not Found
Server: nginx/1.0.9
Date: Sun, 29 Jun 2014 16:17:23 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
2014-06-30 00:17:23 ERROR 404: Not Found.
使用break,不在匹配server{}中的location,由于不存在文件,直接返回404.
配置
location ~ /error.html {
rewrite ^/(.*) /true.html last;
}
location ~ /true.html {
if ( !-e $request_filename ){
return 508;
}
}
[root@A ]# wget -SO /dev/null http:///error.html
--2014-06-30 00:18:59-- http:///error.html
Resolving ... 192.168.1.200
Connecting to |192.168.1.200|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 508
Server: nginx/1.0.9
Date: Sun, 29 Jun 2014 16:18:59 GMT
Content-Length: 0
Connection: keep-alive
2014-06-30 00:18:59 ERROR 508: (no description).
使用last,重新匹配server{}中的location,返回匹配到location ~ /true.html 中的508.
阅读(432) | 评论(0) | 转发(0) |