Nginx使用proxy_pass忽略access_by_lua_file

问题描述

我在我的项目中使用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中没有错误。唯一的一个是我尝试获取空URL。我如何强制Nginx执行access_by_lua_file内容

解决方法

感谢@IvanShatsky。 Rewrite_by_lua对我有效。