On this page
- Why run an image server like imgproxy?
- How do you generate the signing key and salt?
- How do you start imgproxy with Docker Compose?
- How do you build and sign an imgproxy URL?
- How do you cache results and add HTTPS with Nginx?
- How do you serve WebP and AVIF automatically?
- How do you keep imgproxy safe and fast?
- What do typical imgproxy errors mean?
- Questions
Why run an image server like imgproxy?
imgproxy takes an original image from a URL or a local folder, processes it with the libvips library and returns the result, so you store one master file and request any size or format through the address. It is fast and frugal with memory, which suits a small VPS well.
Typical uses are responsive thumbnails for a shop or blog, converting uploads to WebP or AVIF, and smart cropping for preview cards. Because every variant is computed on request, put a cache in front of it; that is part of this guide.
Requirements are modest: 1 vCPU and 1 GB of memory serve a small site, and 2 vCPU with 2 to 4 GB handle frequent large originals. You need Docker (Docker Engine tutorial, or the ready Docker image) and a DNS name such as img.example.net.
How do you generate the signing key and salt?
Signed URLs stop outsiders from asking your server to resize arbitrary images in endless sizes, which would burn CPU and transfer. Create two random hex strings:
openssl rand -hex 32
openssl rand -hex 32The first becomes the key, the second the salt. Store them in /opt/imgproxy/.env with mode 600, and give the same values to the application that builds image URLs:
IMGPROXY_KEY=first-hex-value
IMGPROXY_SALT=second-hex-value
IMGPROXY_ALLOWED_SOURCES=https://cdn.example.net/,local://
IMGPROXY_LOCAL_FILESYSTEM_ROOT=/images
IMGPROXY_MAX_SRC_RESOLUTION=40
IMGPROXY_QUALITY=82
IMGPROXY_TTL=2592000IMGPROXY_ALLOWED_SOURCES keeps the server from fetching images from anywhere else. IMGPROXY_MAX_SRC_RESOLUTION (in megapixels) rejects absurdly large originals, and IMGPROXY_TTL sets the Cache-Control lifetime in seconds.
How do you start imgproxy with Docker Compose?
Save this as /opt/imgproxy/compose.yaml. The volume exposes a folder of originals read-only; leave it out if all images come from a remote origin.
services:
imgproxy:
image: ghcr.io/imgproxy/imgproxy:latest
restart: unless-stopped
env_file: .env
ports:
- "127.0.0.1:8080:8080"
volumes:
- /srv/images:/images:rosudo mkdir -p /srv/images
cd /opt/imgproxy
docker compose up -d
docker compose images
curl -s http://127.0.0.1:8080/healthThe health endpoint replies that imgproxy is running. docker compose images shows which tag you are on; pin that tag in the Compose file once you are happy with it.
How do you build and sign an imgproxy URL?
A URL has three parts: a signature, processing options and the source. The signature is an HMAC-SHA256 of the salt followed by the path, using the key, encoded as URL-safe base64 without padding. This shell snippet computes it (install xxd with sudo apt install xxd, or sudo dnf install vim-common on Rocky and Alma):
KEY=first-hex-value
SALT=second-hex-value
P="/rs:fit:600:0/plain/local:///shop/mug.jpg@webp"
SIG=$( { echo -n "$SALT" | xxd -r -p; printf %s "$P"; } | openssl dgst -sha256 -mac HMAC -macopt hexkey:$KEY -binary | base64 | tr +/ -_ | tr -d =)
echo "http://127.0.0.1:8080/$SIG$P"
curl -s -o /tmp/mug.webp -w "%{http_code} %{content_type}\n" "http://127.0.0.1:8080/$SIG$P"Copy a test image to /srv/images/shop/mug.jpg first. A 200 image/webp reply proves both signing and processing work. In the options, rs:fit:600:0 means resize to fit 600 pixels wide with automatic height; rs:fill:300:300 crops to a square and g:sm adds smart gravity for the crop. Client libraries for PHP, Python, Node.js and others produce the same signatures, so your application rarely needs this shell form.
How do you cache results and add HTTPS with Nginx?
imgproxy itself keeps no cache, so Nginx stores each processed variant on disk and serves repeats without touching the container. Install Nginx and Certbot (sudo apt install nginx certbot python3-certbot-nginx; on Rocky or Alma install epel-release first, use dnf, and run sudo setsebool -P httpd_can_network_connect 1). Then write /etc/nginx/conf.d/imgproxy.conf:
proxy_cache_path /var/cache/nginx/imgproxy levels=1:2 keys_zone=imgcache:50m
max_size=5g inactive=30d use_temp_path=off;
server {
listen 80;
listen [::]:80;
server_name img.example.net;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_cache imgcache;
proxy_cache_valid 200 30d;
proxy_cache_lock on;
proxy_cache_use_stale error timeout updating;
add_header X-Cache-Status $upstream_cache_status;
}
}sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d img.example.net
sudo ufw allow 80,443/tcpOn Rocky and Alma use sudo firewall-cmd --permanent --add-service=https --add-service=http and sudo firewall-cmd --reload instead of ufw. Request the same signed URL twice through https://img.example.net with curl -I; the second answer should carry X-Cache-Status: HIT.
How do you serve WebP and AVIF automatically?
Two approaches exist. The explicit one, used above, appends @webp or @avif to the source, so each format has its own URL and caches cleanly. The automatic one sets IMGPROXY_AUTO_WEBP=true and IMGPROXY_AUTO_AVIF=true, after which imgproxy picks a format from the browser Accept header.
With automatic selection, the same URL returns different bytes per browser, so the Nginx cache key must include that choice. A small map keeps the key short:
map $http_accept $img_fmt {
default "";
"~image/avif" "avif";
"~image/webp" "webp";
}Place the map above the server block and add proxy_cache_key "$scheme$host$request_uri$img_fmt"; to the location. AVIF encoding costs noticeably more CPU than WebP, which is another reason the cache matters.
How do you keep imgproxy safe and fast?
- Keep the key and salt secret; anyone with them can request any size from your allowed sources.
- Limit originals with
IMGPROXY_MAX_SRC_RESOLUTIONand, for remote sources,IMGPROXY_MAX_SRC_FILE_SIZEin bytes. - Set
IMGPROXY_WORKERSto about twice the number of vCPU if you need to cap concurrency. - Watch CPU and outgoing transfer with usage monitoring; a busy image host is often limited by transfer before CPU.
To update, pull the newer tag and recreate the container with docker compose pull and docker compose up -d. Clear the Nginx cache only when output really changes, for example after a quality setting change: sudo rm -rf /var/cache/nginx/imgproxy/* followed by sudo systemctl reload nginx.
What do typical imgproxy errors mean?
- 403 Invalid signature: key or salt differ between imgproxy and the code that signs, or the path was changed after signing (including URL encoding of the source).
- 404 or 422 for a source: the origin is not listed in
IMGPROXY_ALLOWED_SOURCES, the file does not exist, or the origin returned an error. - Source image resolution is too big: raise
IMGPROXY_MAX_SRC_RESOLUTIONcarefully or shrink the master. - Every request is a MISS: the cache key includes a changing header or the response sets no-cache; read
docker compose logs imgproxyand the Nginx error log.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about imgproxy image resizing
Can imgproxy read images from object storage?
Yes, it supports S3-compatible and other storage back ends through its own settings. We do not offer object storage, so point it at your existing bucket or use the local folder method.
Should I disable signatures during development?
Without a key and salt imgproxy accepts the word insecure in place of a signature. Use that only on a private test box, never on a public host.
Does imgproxy strip metadata?
By default it removes EXIF and similar metadata from results, which shrinks files and avoids leaking camera or location details.
Can I add a watermark?
Set IMGPROXY_WATERMARK_PATH to an image inside the container and use the wm option in the URL to place it with chosen opacity and position.
How large should the Nginx cache be?
Start with a few gigabytes and check du -sh /var/cache/nginx/imgproxy after a week. Leave room on disk for logs and originals as well.
More in Self-hosted apps
- Nextcloud on Nginx
- ownCloud Infinite Scale
- Seafile file sync
- Vaultwarden password vault
- Passbolt team password manager
- Gitea Git hosting
- Forgejo Git server
- GitLab Community Edition
- Gogs Git service
- Wiki.js
- BookStack documentation
- Outline knowledge base
- Paperless-ngx documents
- n8n workflow automation
- Activepieces automation
- Plausible Analytics (Community Edition)
- Umami analytics
- Mattermost team chat
- Matrix Synapse with Element
- Jitsi Meet video calls
- ONLYOFFICE Docs with Nextcloud
- HashiCorp Vault secrets server
- OpenBao secrets management
- Infisical secrets manager
- Authelia SSO and forward auth
- Zitadel identity platform
- VS Code in the browser (code-server)
- Joplin Server for notes sync
- Firefly III personal finance
- Snipe-IT asset tracking
- Odoo ERP on Ubuntu or Debian
- ERPNext with frappe_docker
- Dolibarr ERP and CRM with Nginx
- Penpot design tool with Docker
- Planka kanban boards
- Leantime project management
- Wekan boards with Docker
- Cal.com scheduling
- Chatwoot support inbox
- Mautic marketing automation
- DocuSeal document signing
- Metabase dashboards
- Appwrite backend server
- Self-hosted Supabase
- PocketBase backend
- RustDesk relay server
- Traccar GPS tracking
- Redmine project tracker
- The Lounge IRC client
- CyberChef data toolbox
- Typebot chat forms
- AFFiNE workspace
- Overleaf Community Edition
- Neko shared virtual browser
- NetBox network inventory
- UVdesk help desk
- YetiForce CRM