Extensions icon indicating copy to clipboard operation
Extensions copied to clipboard

[Help] How to access images processed by Nginx + Image Proxy extension through imgproxy?

Open SuperNG6 opened this issue 8 months ago • 1 comments

How to access images processed by Nginx + Image Proxy extension through imgproxy?

Thank you very much to the FreshRSS team and the Image Proxy extension developer.

I have a requirement to compress images from feeds using imgproxy. I have already solved part of the cross-domain issue for feed images through nginx + Image Proxy extension, but some images are too large and load too slowly. Therefore, I want to convert them first, such as converting them to webp/avif. However, after debugging my Nginx configuration for three days, I still can't solve it and need help.

My docker imgproxy

  imgproxy:
    image: darthsim/imgproxy:latest
    environment:
      - IMGPROXY_QUALITY=80
      - IMGPROXY_FORMAT_QUALITY=jpeg=85,webp=75,avif=65
      - IMGPROXY_AUTO_WEBP=true
      - IMGPROXY_AUTO_AVIF=true
      - IMGPROXY_ENFORCE_AVIF=true
      - IMGPROXY_TTL=2592000
      - IMGPROXY_USE_ETAG=true
      - IMGPROXY_MAX_SRC_RESOLUTION=50
      - IMGPROXY_MAX_SRC_FILE_SIZE=20971520
      - IMGPROXY_CACHE_CONTROL_PASSTHROUGH=true
      - IMGPROXY_JPEG_PROGRESSIVE=true
      - IMGPROXY_PNG_INTERLACED=true
      - IMGPROXY_ALLOW_ORIGIN= "*"
    volumes:
      - ./Shanghai:/etc/localtime:ro
    restart: unless-stopped

This is my imgproxy nginx configuration

map $http_accept $preferred_format {
    ~*avif                     "avif";
    ~*webp                     "webp";
    default                    "original";
}

server {
    listen                     5023;
    server_name                myrss.com;


    location /imgproxy {
        if ($arg_key != "xxxxxxxxxxxxx") {
            return 404;
        }
        proxy_pass http://imgproxy-ip:8080/insecure/plain/http://imgproxy-geteway-ip:5022/proxy?url=$arg_url;


        proxy_set_header       Accept "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8";

        proxy_set_header       X-Real-IP $remote_addr;
        proxy_set_header       X-Real-Port $remote_port;
        proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header       HTTP_X_FORWARDED_FOR $remote_addr;
        proxy_set_header       X-Forwarded-Proto $scheme;
        proxy_set_header       Host $host;
        proxy_set_header       X-NginX-Proxy true;

        proxy_redirect ~^(.*)$ https://myrss.com/imgproxy?key=$arg_key&url=$1;
        proxy_ssl_server_name on;

        set_real_ip_from 0.0.0.0/24;
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;

    }

    location =/robots.txt {
        default_type           text/html;
        add_header             Content-Type "text/plain; charset=UTF-8";
        return                 200 "User-Agent: *\nDisallow: /";
    }

   
    access_log                 /var/log/nginx/imgproxy-access.log;
    error_log                  /var/log/nginx/imgproxy-error.log;
}

My freshrss-imageproxy Nginx configuration

server {
    listen                     5022;
    server_name                myrss.com;

    location /proxy {
        if ($arg_key = "xxxxxxxxxxxxx") {
            proxy_pass $arg_url;
        }
        # Handle redirects coming from the target server.
        proxy_redirect ~^(.*)$ https://myrss.com/proxy?key=$arg_key&url=$1;
        proxy_ssl_server_name on;
    }
}

SuperNG6 avatar Apr 19 '25 01:04 SuperNG6

I'm not entirely clear on what the question is. You mean you can't get the conversion as such to work when manually loading an image URL?

Frenzie avatar Apr 19 '25 11:04 Frenzie