Nginx redirect not working if using cloudflare

I’m using nginx to do a redirect if a user direct access image by browser. The problem is it doesn’t work when you use Cloudflare, it will no longer redirect. Here is a live version for you to test with: link

nginx config

 location ~ "^/c/600x1200_90_webp/img-master/img/\d+/\d+/\d+/\d+/\d+/\d+/((?<filenum>\d+)[^/]+\.(jpg|png|webp))$" {
    proxy_pass http://195.xxx.xxx.xxx:5694;
    valid_referers server_names demo.adoreanime.com;
    if ($invalid_referer = "1") {
    add_header Cache-Control "no-cache";
    return 301 https://demo.adoreanime.com/artwork/$filenum; 
}
    }

Is there anyway to fix this without disabling Cloudflare? I want to still able to cache and redirect

To cache with the “no-cache”? :thinking:

Is your origin working over HTTPS or not?

What error do you get?

And your app is listening on some of the supported and compatible ports with Cloudflare :orange:?

1 Like

Yes it works over HTTPS.
There are no errors.
I’m not running any app since it’s just a reverse proxy site on port 5694

@fritex here’s a live link for you to test with. It seems to be giving a 304 status

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.