Nginx忽略使用proxy_pass的access_by_lua_file

我在我的项目中使用OpenResty,遇到了nginx忽略access_by_lua_file的问题当使用proxy pass。这是我的位置代码:

    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就忽略它。并且错误日志中没有错误。唯一的错误是我试图获取空URL。我怎样才能强制nginx执行access_by_lua_file的内容呢?

点赞
用户2818150
用户2818150

感谢 @IvanShatsky。 通过使用 rewrite_by_lua,对我有效。

2020-11-12 12:33:52