玩了一段server 很是舒服,nginx 更是大杀器,记录下有趣地方

 

1. 可以直接返回简单结果

如果我们需要用nginx 处理文件请求 存在直接返回文件  不存在则返回 错误json,

在http中 我们可以这样写

location ~* /images/(\w\w)(\w\w)(\w+)/exists {

  if (-f /xx/xx/xx/$1/$2/$1$2$3)

  {

  return 200 '{"code":"1","result":"xxxx"}' ;

  }

  return 404 '{"code":"-1","result":"xxxx"}' ;

}

 

location ~*/images/(\w\w)(\w\w)(\w+){

 alias /xx/xx/xx/$1/$2/$1$2$3 ;

 error_page 404 /error;

}

location /error

{

  alias xxx/xxx/error.json

 or

 return 404 '{"code":"-1","result":"xxxx"}' ;

}

1 location ~* /images/(\w\w)(\w\w)(\w+) {
2 
3   if
4 
5 }

 

2. 设置默认返回类型  这是个好东西啊

default_type application/json ;

这样浏览器知道用json 去解析

 

额 剩下的想起来在写

 

 

 

 posted on 2012-11-22 16:35  沐訫  阅读(423)  评论(0编辑  收藏  举报