Image Resizing Cloudflare

Im having problems with redirect on nginx

I have this original URL:

https://www.example.com/media/wysiwyg/logo.png

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

https://www.example.com/cdn-cgi/image/onerror=redirect/media/wysiwyg/logo3.png

But i need this dynamic, like:

Everything in this folder: “media/wysiwyg/” will redirected to:

https://www.example.com/cdn-cgi/image/format=auto,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:

https://www.example.com/media/wysiwyg/logo.png

I need redirect to this (without change url):

https://www.example.com/cdn-cgi/image/format=auto,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:
https://zone/cdn-cgi/image/options/source-image

It looks like you have a circular redirect:
Requests to https://www.example.com/media/wysiwyg/logo.png get redirected to https://www.example.com/cdn-cgi/image/onerror=redirect/media/wysiwyg/logo.png which makes Cloudflare request an image from https://www.example.com/media/wysiwyg/logo.png 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
https://www.example.com/cdn-cgi/image/f=auto,q=75/media/wysiwyg/logo.png but without change this url:

https://www.example.com/media/wysiwyg/logo.png

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 https://www.example.com/original/wysiwyg/logo.png, and then proxy requests from Nginx to https://www.example.com/cdn-cgi/image/f=auto,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.