37#37: *146039 rewrite or internal redirection cycle while internally redirecting to "/static/js/main.64520b4a.js"

Viewed 42

While checking the GCP error log i got a issue (rewrite or internal redirection cycle).

I cannot figure out why this error is happening: "146039 rewrite or internal redirection cycle while internally redirecting to "/static/js/main.64520b4a.js" in nginx.conf

Below is my Config file:

server {  
  listen 80 default_server;   
  listen [::]:80 default_server;  
  root /var/www/html;  
  server_tokens off;  
  
  location / {  
    if (-f $document_root/$maintenance_mode) {  
      rewrite ^(.*)$ /maintenance_page.html break;  
    }  
    try_files $uri /index.html =404;  
    proxy_set_header Host $host;  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    proxy_set_header X-Request-URI $request_uri;  
  }  
  
  location ~ .(static)/(js|css|media)/(.+)$ { 
    try_files $uri $uri/ /$1/$2/$3;  
  }  
}

guys if you know the solution, kindly share

1 Answers

You're try_files statement is redirecting to /$1/$2/$3 which causes the continuous loop.

If the /$1/$2/$3 is intended to be a file term (see this document) - then it cannot be the final parameter.

For example, you could append =404 to create a valid try_files statement:

try_files $uri $uri/ /$1/$2/$3 =404;
Related