ngx.log after ngx.redirect

164 views
Skip to first unread message

fitstek

unread,
Feb 29, 2016, 6:46:42 AM2/29/16
to openresty-en

Hi,


I was wondering if this is a bug or not. 


          set $x 'true';

          rewrite_by_lua '

            ngx.var.x = "false"

            ngx.log(ngx.NOTICE, "Value of x: ", ngx.var.x)

            ngx.redirect("http://redirectedurl.com", 301)

          ';

The above configuration works and I get the notice in my log. 

But when I move the redirect to the first line it stops working. Why is that?

          set $x 'true';

          rewrite_by_lua '

            ngx.redirect("http://redirectedurl.com", 301)

            ngx.var.x = "false"

            ngx.log(ngx.NOTICE, "Value of x: ", ngx.var.x)

          ';

Hamish Forbes

unread,
Feb 29, 2016, 9:53:53 AM2/29/16
to openresty-en
The docs explain this pretty clearly: https://github.com/openresty/lua-nginx-module#ngxredirect

Note that this method call terminates the processing of the current request and that it must be called before ngx.send_headers or explicit response body outputs by either ngx.print or ngx.say.

It is recommended that a coding style that combines this method call with the return statement, i.e., return ngx.redirect(...) be adopted when this method call is used in contexts other than header_filter_by_lua to reinforce the fact that the request processing is being terminated.

Fitsum Teklehaimanot

unread,
Feb 29, 2016, 9:57:29 AM2/29/16
to openre...@googlegroups.com
Thanks, must have completely skipped over that.

--
You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/fjJbH2V9-no/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages