Enable CORS in NGINX.Config as a reverse proxy but not working

Hi Team

I enabled a CORS in NGINX.Config. But getting an error while integrating in angular application.

Reverse proxy working fine.

ERROR:- has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request.

Can anyone assist where its missing.

NGINX.Config

 server {
          root /usr/share/nginx/www;
          index index.html index.htm;
          location /grafana/ {
          rewrite  ^/grafana/(.*)  /$1 break;
          proxy_set_header Host $http_host;
          proxy_pass http://grafana;
          if ($http_origin ~ '^https?://(example\.com/grafana/\?orgId=1)
```) {
                set $cors 'true';
          }
          if ($cors = 'true') {
              add_header 'Access-Control-Allow-Origin' "$http_origin" always;
              add_header 'Access-Control-Allow-Credentials' 'true' always;
              add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
              add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep- 
              Alive,Origin,User-Agent,X-Requested-With' always;
              # required to be able to read Authorization header in frontend
              #add_header 'Access-Control-Expose-Headers' 'Authorization' always;
          }
          if ($request_method = 'OPTIONS') 
          {
              add_header 'Access-Control-Allow-Origin' '*';
              #
              # Om nom nom cookies
              #
              add_header 'Access-Control-Allow-Credentials' 'true';
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
              
              #
              # Custom headers and headers various browsers *should* be OK with but aren't
              #
              add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified- 
              Since,Cache-Control,Content-Type';
              
              #
              # Tell client that this pre-flight info is valid for 20 days
              #
              add_header 'Access-Control-Max-Age' 1728000;
              add_header 'Content-Type' 'text/plain charset=UTF-8';
              add_header 'Content-Length' 0;
          }
          if ($request_method = 'POST') {
              add_header 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Credentials' 'true';
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
              add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified- 
              Since,Cache-Control,Content-Type';
          }
          if ($request_method = 'GET') {
              add_header 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Credentials' 'true';
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
              add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified- 
              Since,Cache-Control,Content-Type';
          }
          }

is this an error in the Grafana logs?

try increasing the verbosity of the Grafana server logs to debug and note any errors. For printing to console, set the console logs to debug as well.