Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36175
  • 博文数量: 14
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 164
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-17 15:58
个人简介

~

文章分类

全部博文(14)

文章存档

2015年(9)

2014年(4)

2013年(1)

我的朋友

分类: 系统运维

2014-07-13 22:10:57

        前提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) |
给主人留下些什么吧!~~