Welcome! Log In Create A New Profile


Re: ngx_http_script_run() question

Maxim Dounin
July 18, 2022 10:32PM

On Mon, Jul 18, 2022 at 04:02:53PM +0100, Chris Newton via nginx-devel wrote:

> I'm adding a variable that wants to provide an absolute URL to proxy_pass,
> whose value is based in part on a database lookup - but if the search key
> is not found in that database, my handler function is returning an
> NGX_ERROR which seemed reasonable (there is no good default I can return),
> so just causing a 500 error at that point is not unreasonable.
> However, that also causes an error to be logged by ngx_http_proxy_eval()
> for every request, which i'd like to avoid.

NGX_ERROR means a fatal error and it is expected to be logged -
by the code where the error appears. Right now scripting
infrastructure silently converts errors from variable handlers to
empty values - but this is something to change, since this
isn't a safe approach and can cause various issues. Consider
returning a value instead - something like an empty value or a
value with the not_found flag.

The logging you see is, however, unrelated. It's
ngx_http_proxy_eval() which complains about an invalid URL after
variable evaluation. That's because proxy_pass is expected to be
reasonably configured to always result in a valid URL. If it
doesn't, this is considered to be a configuration error and
reported, both to the user with 500 (Internal Server Error) and to
the error log.

If in your case a valid URL for proxying is not always available,
consider re-configuring nginx to avoid the error condition. In
particular, providing a dummy URL which immediately returns an
error or an explicit check before proxying might be considered.

Maxim Dounin
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

ngx_http_script_run() question

Chris Newton via nginx-devel 284 July 18, 2022 11:04AM

Re: ngx_http_script_run() question

Maxim Dounin 102 July 18, 2022 10:32PM

Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 59
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready