【问题标题】:Nginx internally call another request and return that request dataNginx 内部调用另一个请求并返回该请求数据
【发布时间】:2019-02-03 17:25:32
【问题描述】:

我正在使用 nginx 和 lua 来解析我的 rest api (https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/) 。我试图在我的 rest 调用中内部调用另一个 api,它是一个不同的服务器并返回该响应。但它总是得到空洞的回应。以下是我的配置,我请求 /student 任何帮助都是非常可观的

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;
}

【问题讨论】:

    标签: nginx lua nginx-reverse-proxy openresty nginx-config


    【解决方案1】:

    尝试将您的位置/学生更改为

    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)
        ';
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-24
      • 2021-04-03
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      相关资源
      最近更新 更多