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 去解析

    额 剩下的想起来在写

  • 相关阅读:
    xadmin 安装
    Python
    使用免费证书安装 ipa 到真机
    Jupyter PPT
    Javascript注意点
    论文哪里找?
    神经网络术语
    PyTorch上路
    DCGAN实现
    数据库和数据挖掘领域的会议和期刊
  • 原文地址:https://www.cnblogs.com/trigged/p/2782889.html
Copyright © 2011-2022 走看看