1

I use OpenResty in my project and faced issue that nginx ignores access_by_lua_file when use proxy pass. Here is my code of location:

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

I call this location with ngx.location.capture. In lua file i define variables apiauth and api_host. But contents of lua file never executes, nginx just ignores it. And no errors in error.log. The only one is that i try to GET empty URL. How can i force nginx to execute contents of access_by_lua_file?

2
  • 1
    According to the request execution flow access_by_lua handler should be executed even when you generate response content via the proxy_pass directive, but you'd better change it to rewrite_by_lua or even better rewrite your code to be used via set_by_lua (the last one used somehow different syntax, you must return the value that should be assigned to the variable, check the examples). Commented Nov 12, 2020 at 12:17
  • @IvanShatsky thanks, rewrite_by_lua works for me. Commented Nov 12, 2020 at 12:32

1 Answer 1

2

Thanks to @IvanShatsky. Rewrite_by_lua works fo me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.