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.
I can make a change to ngx_http_proxy_eval() :
*--- a/nginx/files/nginx/src/http/modules/ngx_http_proxy_module.c*
*+++ b/nginx/files/nginx/src/http/modules/ngx_http_proxy_module.c*
@@ -1098,9 +1098,10 @@ ngx_http_proxy_eval(ngx_http_request_t *r,
ngx_http_proxy_ctx_t *ctx,
     ngx_url_t             url;
     ngx_http_upstream_t  *u;
     if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0,
                             plcf->proxy_values->elts)
-        == NULL)
+        == NULL || proxy.len == 0)
     {
         return NGX_ERROR;
     }
although I think it might be good to make a more general fix - ie., have
ngx_http_script_run() return NULL if there was no output from the script:
*--- a/nginx/files/nginx/src/http/ngx_http_script.c*
*+++ b/nginx/files/nginx/src/http/ngx_http_script.c*
@@ -641,6 +641,9 @@ ngx_http_script_run(ngx_http_request_t *r, ngx_str_t
*value,
         len += lcode(&e);
     }
+    if (len == 0) {
+        return NULL;
+    }
Would that be a reasonable change to make ?
TIA
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20220718/ab4ffd1e/attachment.htm>