log_by_lua and proxy_intercept_errors

74 views
Skip to first unread message

Arvind Jayaprakash

unread,
Feb 18, 2015, 1:20:17 AM2/18/15
to openre...@googlegroups.com
I have log_by_lua and proxy_intercept_errors enabled for a given location. The error_page lies outside this block. Here is the example:


server {
    error_page 500 502 503 504 =200 @err;
    location /tmp {
        log_by_lua '
        ngx.log(ngx.ERR, "upstream fu ", ngx.var.upstream_time, " bar")
        ';
        proxy_pass http://172.17.42.1:80;
        proxy_intercept_errors on;
    }

    location @err {
        rewrite ^ /err.html last;
    }
}



The problem is that the log_by_lua does not run when the upstream returns an error. This does not happen if proxy_intercept_errors is turned off. Is there any workaround for this?

Yichun Zhang (agentzh)

unread,
Feb 18, 2015, 2:49:18 PM2/18/15
to openresty-en
Hello!

On Tue, Feb 17, 2015 at 10:20 PM, Arvind Jayaprakash wrote:
>
> The problem is that the log_by_lua does not run when the upstream returns an
> error. This does not happen if proxy_intercept_errors is turned off. Is
> there any workaround for this?
>

proxy_intercept_errors initiates an "internal redirect" to a new
location (location @err in your case), so you need to configure
log_by_lua in that location because the original location is already
quit by the current request upon internal redirects (internal
redirects work like the "exec" command in shell, overriding the old
configurations in place).

Regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages