Nginx 忽略 access_by_lua_file 和 proxy_pass

Nginx ignores access_by_lua_file with proxy_pass

我在我的项目中使用了 OpenResty 并遇到了 nginx 在使用代理传递时忽略 access_by_lua_file 的问题。这是我的位置代码:

    location /getapi {
                    internal;
                    set $apiauth '';
                    set $api_host '';
                    access_by_lua_file /usr/local/openresty/nginx/conf/lua/getapi.lua;
                    proxy_redirect default;
                    proxy_pass $api_host;
                    proxy_ssl_certificate "/usr/local/openresty/nginx/conf/cert.pem"
certificate_key "cert.key";
                    proxy_set_header Host $http_host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Authorization $apiauth;
                }

我用 ngx.location.capture 称呼这个位置。在 lua 文件中,我定义了变量 apiauthapi_host。但是 lua 文件的内容永远不会执行,nginx 只是忽略它。 error.log 中没有错误。唯一的一个是我尝试 GET empty URL。我如何强制nginx执行access_by_lua_file的内容?

感谢@IvanShatsky。 Rewrite_by_lua 适合我。