Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX health check requires an upstream

I have a location like:

location / {
set $api_name "Web";

proxy_intercept_errors on;

set $upstream upstream_a;

if ( $kms_in_cookie != "not_set" ) {
    set $upstream $kms_in_cookie;
}

if ( $upstream_in_cookie != "not_set" ) {
    set $upstream $upstream_in_cookie;
}

if ($cookie_zak != "") {
    set $upstream upstream_b;
}

proxy_pass http://$upstream;

health_check uri=/healthcheck  interval=30 fails=3 passes=3;}

Once I restart my NGINX, it failed:

nginx: [emerg] health check requires an upstream in

Any one has a idea about this? What does this error mean?

like image 451
Lei Zhao Avatar asked Oct 28 '22 06:10

Lei Zhao


1 Answers

I had the same issue. From experimenting with it the issue appears to be the variable name in the proxy_pass directive. If you use the name of a valid upstream the issue is resolved.

Clearly you are trying to direct traffic based on some request meta-data, and the above advice wont help with this. Your scenario is not an uncommon one so I would expect this to work. Looks like a bug in nginx, or at the very least a gap in the documentation.

like image 200
Stephen Dunne Avatar answered Jan 02 '23 20:01

Stephen Dunne