Skip to content

XDS creation

Le roi edited this page Nov 24, 2018 · 2 revisions

Use this tutorial to process the xds body and make routing decisions based on the node id and cluster id found in the request body.

To install the nginx lua module on debian, run the following

sudo apt-get install nginx-extras

https://yos.io/2016/01/28/building-an-api-gateway-with-lua-and-nginx/

server { listen 8080; server_name localhost;

# To allow POST on static pages
error_page  405     =200 $uri;

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

location /example {
    client_body_in_single_buffer on;
    client_body_in_file_only off;
    client_body_buffer_size 8K;
    client_max_body_size 8K;

    content_by_lua '
        ngx.req.read_body()

        if ngx.re.match(ngx.var.request_body, "\\\"abc\\\"") then 
            ngx.exec("/abc.json")
        elseif ngx.re.match(ngx.var.request_body, "\\\"xyz\\\"") then 
            ngx.exec("/xyz.json")
        else
            ngx.status = 404
            ngx.exit(ngx.OK)
        end 
    ';
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

}

Clone this wiki locally