For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

arian's avatar
arian
Icon for Nimbostratus rankNimbostratus
Aug 31, 2022

NGINX Plus health_check doesn't support $proxy_host

It seems like NGINX Plus's health_check directive doesn't support variable hosts. (I'm on R24)

We can see here that the default is $proxy_host:

 

proxy_set_header Host       $proxy_host;

 

However, when using health_check and setting the Host header via a variable, it doesn't respect the context within the location block.

 

server {
  listen 8080;
  server_name localhost;
  
  set $proxy_host $host;
  proxy_set_header Host $proxy_host;

  location /api/notworking {
    # Set host for just this block only
    set $proxy_host "override-api-not-working.host.com";

    # proxy_pass gets correct "Host: override-api-not-working.host.com"
    # so below works perfectly fine
    proxy_pass http://localhost:8000;

    # !!! health_check does not get correct host here!!!
    health_check uri=/__health?from=nginx passes=3 interval=5s fails=3;
  }
}

 

 However it works just fine if you set the host via proxy_set_header

 

server {
  listen 8080;
  server_name localhost;
  
  set $proxy_host $host;
  proxy_set_header Host $proxy_host;

  location /api/working {
    # Set host for just this block only
    proxy_set_header Host "override-api-working.host.com";

    # proxy_pass gets correct "Host: override-api-working.host.com"
    # so below works perfectly fine
    proxy_pass http://localhost:8000;

    # health_check gets correct "Host: override-api-working.host.com"
    health_check uri=/__health?from=nginx passes=3 interval=5s fails=3;
  }
}

 

 

3 Replies