使用lua远程请求nginx

我尝试在我的nginx.conf文件中运行一个Lua代码,并通过proxy_pass连接到另一个Web应用程序,根据HTTP结果呈现某些资源。

以下是我的代码:

location /_auth {
    proxy_set_header  Accept-Encoding  "";
    proxy_pass http://127.0.0.1:8080/Welvi-rest;
}
location /server/ {
    content_by_lua "
        local res = ngx.location.capture('/_auth');
        ngx.print(res.status);
        if res.status ~= ngx.HTTP_OK then
            ngx.exit(ngx.HTTP_FORBIDDEN)
        end
    ";
}

但是我不知道为什么端口8080上的Web应用服务器从未被调用。

我阅读了一些相关的问题,发现是因为我们需要在Lua中添加头文件,但是我找不到解决此问题的方法。

点赞