学习nginx echo module写的demo

注意: 本站使用的nginx反向代理架设的Https

  1. /api/hello 简单hello world

                    
    location = /api/hello {
        echo "hello, world!";
    }
                    
                
  2. /api/proxy_before_after 反向代理添加前置、后置内容

                    
    # 反向代理添加前置、后置内容
    location = /api/proxy_before_after {
        echo_before_body echo_before_body;
        echo_before_body echo_before_body;
        proxy_pass http://127.0.0.1;
        echo_after_body echo_after_body;
        echo_after_body echo_after_body;
    }
                    
                
  3. /api/sleep/秒 sleep测试

                    
    # sleep测试
    location ~* ^/api/sleep(\/\d*\/?)?$ {
        echo "{";
        echo "  request_uri=$request_uri";
    
        set $time 2;
        if ($uri ~* ^(.+?)/(\d+)/?$) {
            set $time $2;
        }
    
        echo_sleep   $time;
        echo "  time=$time";
        echo "}";
    }
                    
                
  4. /api/combo?file1,file2 模拟combo

                    
    # 模拟combo
    location = /api/combo {
        echo_foreach_split ',' $query_string;
            echo "/* combo: $echo_it */";
            echo_location_async $echo_it;
            echo;
        echo_end;
    }
                    
                
  5. /api/echo/内容 输出内容

                    
    # 输出内容
    location ~* ^/api/echo(\/[^\/]*?\/?)?$ {
        set $str 'null';
        if ($uri ~* ^/api/echo/([^\/]+)/?$) {
            set $str $1;
        }
        echo $str;
    }
                    
                
  6. /api/dump/path?a=1&中文=好的#123 打印nginx变量

  7. /api/cache/?r=时间缀 查看 nginx proxy cache 变量, 由于有缓存, 请添加时间缀来查看最新响应的内容~


有任何问题可在: https://github.com/xuexb/echo.xuexb.com/issues 反馈给我~ 感谢~


link