Rewrite or internal redirection cycle while redirect to named location "@rewrites"

Hi

I think my problem is with NGINX rather than Lucee but it is just odd. At the moment I am getting the following error from Nginx when proxying to Lucee.

rewrite or internal redirection cycle while redirect to named location "@rewrites", client: 127.0.0.1, server: example.local, request: "GET /security HTTP/1.1", host: "example.local"

Here is my Nginx proxy conf, and I can navigate to http://127.0.0.1:8052 fine.

location / {
  # Rewrite rules and other criterias can go here
  # Remember to avoid using if() where possible (http://wiki.nginx.org/IfIsEvil)
  try_files $uri $uri/ @rewrites;
}

location @rewrites {
  rewrite ^/(.*)? /index.cfm/$1 last;
}

location ~* \.(cfm|cfc|cfr)$ {
    set $path_info $request_uri;
    proxy_pass http://127.0.0.1:8052;
    proxy_read_timeout 100s;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Tomcat-DocRoot $document_root;
    proxy_set_header X-ModCFML-SharedKey 8DoB0PzqdMn4zo0Y2bq7dzqynbqBVsK0piuNslpNU6982KaiCqVT8X;
    proxy_set_header X-Webserver-Context $lucee_context;
    # FOR SSL
    proxy_set_header    X-HTTPS   'True';
  }

The rewrite rules are copied from my server where this is running fine which in turn came from the examples in the Lucee Docker files lines 9-19

Any help or pointers appreciated.

Andy

1 Like

I’m not sure if those rules work as-is? They have just been left in place, commented out, ever since the initial pull request where they were added?

Here’s an example nginx rewrite that we use for FarCry Core:

    location @farcry {
        rewrite ^([^\.]*)$  /index.cfm?furl=$1 last;
    }

    location / {
        try_files $uri $uri/ @farcry;
    }

The only real differences that I can see is the order, the rewrite location comes before the web root location, and the @farcry rewrite also excludes paths which contain a . character.

Hope that helps.

cheers,
Justin

I’m sure those rules work as-is as I’ve copied them off the live server. I’ve tried the Farcry method but no joy either. Whats odd is that it was working and now its not. I’m going to try a fresh docker and go from there.

This is for a Framework One app if that helps.

Figured it out. It was the proxy location, which I change recently but obviously without restarting Nginx to test.

# Old Lucee proxy handler which broke my app
location ~* \.(cfm|cfc|cfr)$ {
    set $path_info $request_uri;
    proxy_pass http://127.0.0.1:8052;
    proxy_read..........
  }
# New Lucee proxy handler which works
location ~ \.(cfm|cfml|cfc|jsp|cfr)(.*)$ {
    set $path_info $request_uri;
    proxy_pass http://127.0.0.1:8052;
    proxy_read..........
  }
1 Like