Nginx location directive not working when using return

I’m new to this but I thought that this would be pretty straightforward. I am trying to run a Dockerized wordpress on my local machine. I cannot get the /health directive to work. It always returns the wordpress 404 page. This is what my conf looks like:

 server {
  listen 0.0.0.0:8080;
  server_name localhost;

  root /opt/bitnami/wordpress;
  index index.php;

  include mime.types;

  location = /health {
    return 200 "Healthy @ $date_local";
  }

  location = /apple-app-site-association {
    default_type application/json;
  }

  location = /.well-known {
    default_type application/json;
  }

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  if (!-e $request_filename)
  {
    rewrite ^/(.+)$ /index.php?q=$1 last;
  }

  location ~ .php$ {
    fastcgi_pass localhost:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

Source: StackOverflow