Question

I have setup an image reverse proxy for my Nginx and it works. However, I would like to serve an optimized version of the image.

The original URL (being proxied) actually contains query parameters without image extensions such as http://external.server.com/asp/service?k1=v1&k2=v2. I tried trick Cloudflare or pagespeed to treat it as an image and hope one of which could optimize the image. So my new proxied URL is now http://mydomain.com/some/path/image.png?k1=v1&k2=v2. (Config below)

However, it didn't seem to work. Both CF and pagespeed seems to only optimize referenced static images from the serving html, but not ones that are dynamically requested with any url. Is this true? How could I setup so I am able to provide a reverse image proxy to serve optimized images with Nginx? Thanks a million.

server {
    listen 8080;
    proxy_cache CACHE;
    pagespeed on;

    location /some/path/image.png {
      proxy_pass http://external.server.com/asp/service;
    }
}
Était-ce utile?

La solution

I can't answer for how CloudFlare works, but mod_pagespeed can optimize images in two different ways:

  1. Rewrite image URLs found in HTML or CSS statically on a page. In this case the URL itself will be rewritten to something like ximage.png,qk1-v1&k2=v2.pagespeed.ic.Hash.png. And that URL will be served optimized.
  2. InPlaceResourceOptimization, where the image is rewritten and served from the original URL. As you can see from the documentation, this feature is only available for the Apache-version of mod_pagespeed. We are working on porting it to the the Nginx versions.

In general, the first method is more effective, are these URLs not found statically in HTML? Are they dynamically generated in JS?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top