2

I am using nginx and lua to parse my rest api (https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/) . I am trying to internally call another api inside my rest call which is a different server and return that response. But it is getting empty response always. Below is my config, I am requesting for /student any help is highly appreciable

location /student {
    content_by_lua '
    local str = "test"
    local res = ngx.location.capture("/detail",{method = ngx.HTTP_POST, body = str})
    ngx.say(str)
    ';
}
location /detail {
    set $target '104.28.17.1/post';
    set $pass 'Basic Y2l28=';
    lua_need_request_body on;
    content_by_lua '
    proxy_set_header          Host            $host;
    proxy_set_header          X-Real-IP       $remote_addr;
    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
    #access_by_lua '
    proxy_set_header Authorization $pass;
    proxy_set_header Content-Type 'application/x-www-form-urlencoded';
    proxy_set_header Accept '*/*';
    proxy_set_header Connection 'keep-alive';
    proxy_pass http://$target;
}
Cedric
  • 107
  • 15

1 Answers1

0

Try changing your location /student to

location /student {
    content_by_lua '
    local str = "test"
    local res = ngx.location.capture("/detail",{method = ngx.HTTP_POST, body = str})
    ngx.status = 200
    ngx.say(str)
    ngx.exit(ngx.HTTP_OK)
    ';
}