zoukankan      html  css  js  c++  java
  • nginx 点滴

    玩了一段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 去解析

    额 剩下的想起来在写

  • 相关阅读:
    linux命令大全
    IP协议
    TCP、IP、ARP协议之间的工作关系
    程序出现问题后
    HTTP(超文本传输协议)
    多线程
    syslog.conf文件
    logger命令
    gdb
    二、数据的存储结构
  • 原文地址:https://www.cnblogs.com/trigged/p/2782889.html
Copyright © 2011-2022 走看看