Image Resizing Cloudflare

Im having problems with redirect on nginx

I have this original URL:

And i’m using the Cloudflare Image, i can use this to load by Cloudflare Image:

But i need this dynamic, like:

Everything in this folder: “media/wysiwyg/” will redirected to:,onerror=redirect/media/wysiwyg/logo.png

logo.png would be dynamic, BUT MUST BE AN IMAGE (JPEG, GIF, PNG).

I tried this, but without success:

location ~ ^/media/wysiwyg/(.*) { rewrite ^/media/wysiwyg/(.*) /cdn-cgi/image/format=auto,onerror=redirect/media/wysiwyg/$1 break;

I need, if i access this:

I need redirect to this (without change url):,onerror=redirect/media/wysiwyg/logo.png

What’s wrong?

What are you trying to achieve?

What error are you seeing?

The URL format for CF Images is:

It looks like you have a circular redirect:
Requests to get redirected to which makes Cloudflare request an image from which …

And on error you want the user to get redirected to the original URL, which redirects to the cdn-cgi URL etc.

If all you are looking for is format=auto, does Polish not give you this without the extra configuration on Nginx?

1 Like

I need nginx load this url,q=75/media/wysiwyg/logo.png but without change this url:

Instead i change all urls in my site, i’ll just make a redirect to cloudflare resizer. I need optimize the images, so i’ll set the images with quality 75 example. But to do in a easy way i’m doing by nginx,using redirects/or proxy pass, because i want images optimized.

It sounds to me like you just want Cloudflare Polish. This can be enabled using a Page rule or a slider on the Quality tab of the dashboard (Paid account is required). Turning it on in lossy mode will give you q=85 and image conversion. If 85 instead of 75 is acceptable, then that’s the way to go.

You can use image resizing without altering the original URL using a Worker

In your second example you still have a loop, which I suspect will just error every time. You could expose your images on a second URL (like, and then proxy requests from Nginx to,q=75/original/wysiwyg/logo.png, thus avoiding the loop.

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.