Eval#

该模块允许将子请求响应的主体保存到变量中。

加载模块#

main{} 上下文中连接模块:

load_module modules/ngx_http_eval_module.so;

示例配置#

server {
    listen 80;
    server_name localhost;

    location / {
        eval_subrequest_in_memory off;
        eval_override_content_type text/plain;
        eval_buffer_size 4k;
        eval $res {
            rewrite ^(/eval_.*/)(.*)$  /$2 break;
            proxy_pass http://127.0.0.1:8081;
        }

        if ($res ~ "access denied") {
            return 403 $res\n;
        }

        proxy_pass http://127.0.0.1:8082;
    }
}

server {
    listen 8081;

    if ($arg_user != 'Legal') {
        return 403 "access denied";
    }
    return 200 OK;
}

server {
    listen 8082;

    location / {
        root /usr/share/angie/html;
    }
}

附加信息#

详细文档和源代码可在以下地址获取: openresty/nginx-eval-module