Configuration options
imgproxy is Twelve-Factor-App-ready and can be configured using ENV
variables.
URL signature
imgproxy allows URLs to be signed with a key and a salt. This feature is disabled by default, but is highly recommended to be enabled in production. To enable URL signature checking, define the key/salt pair:
IMGPROXY_KEY
: hex-encoded keyIMGPROXY_SALT
: hex-encoded saltIMGPROXY_SIGNATURE_SIZE
: number of bytes to use for signature before encoding to Base64. Default: 32
You can specify multiple key/salt pairs by dividing the keys and salts with a comma (,
). imgproxy will check URL signatures with each pair. This is useful when you need to change key/salt pairs in your application while incurring zero downtime.
You can also specify file paths using the command line by referencing a separate file containing hex-coded keys and salts line by line:
imgproxy -keypath /path/to/file/with/key -saltpath /path/to/file/with/salt
If you need a random key/salt pair really fast, as an example, you can quickly generate one using the following snippet:
echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
IMGPROXY_TRUSTED_SIGNATURES
: a list of trusted signatures, comma divided. When set, imgproxy will trust the signatures from the list and won't check them even ifIMGPROXY_KEY
andIMGPROXY_SALT
are set. Default: blank
Server
IMGPROXY_BIND
: the address and port or Unix socket to listen to. Default::8080
IMGPROXY_NETWORK
: the network to use. Known networks aretcp
,tcp4
,tcp6
,unix
, andunixpacket
. Default:tcp
IMGPROXY_TIMEOUT
: (deprecated alias: IMGPROXY_WRITE_TIMEOUT) the maximum duration (in seconds) for processing the response. Default:10
IMGPROXY_READ_REQUEST_TIMEOUT
: (deprecated alias: IMGPROXY_READ_TIMEOUT) the maximum duration (in seconds) for reading the entire incoming HTTP request, including the body. Default:10
IMGPROXY_WRITE_RESPONSE_TIMEOUT
: the maximum duration (in seconds) for writing the HTTP response body. Default:10
IMGPROXY_KEEP_ALIVE_TIMEOUT
: the maximum duration (in seconds) to wait for the next request before closing the connection. When set to0
, keep-alive is disabled. Default:10
IMGPROXY_CLIENT_KEEP_ALIVE_TIMEOUT
: the maximum duration (in seconds) to wait for the next request before closing the HTTP client connection. The HTTP client is used to download source images. When set to0
, keep-alive is disabled. Default:90
IMGPROXY_DOWNLOAD_TIMEOUT
: the maximum duration (in seconds) for downloading the source image. Default:5
IMGPROXY_WORKERS
: (alias:IMGPROXY_CONCURRENCY
) the maximum number of images an imgproxy instance can process simultaneously without creating a queue. Default: the number of CPU cores multiplied by twoIMGPROXY_REQUESTS_QUEUE_SIZE
: the maximum number of image requests that can be put in the queue. Requests that exceed this limit are rejected with429
HTTP status. When set to0
, the requests queue is unlimited. Default:0
IMGPROXY_MAX_CLIENTS
: the maximum number of simultaneous active connections. When set to0
, connection limit is disabled. Default:2048
IMGPROXY_TTL
: a duration (in seconds) sent via theCache-Control: max-age
HTTP header. Default:31536000
(1 year)IMGPROXY_CACHE_CONTROL_PASSTHROUGH
: whentrue
and the source image response contains theExpires
orCache-Control
headers, reuse those headers. Default: falseIMGPROXY_SET_CANONICAL_HEADER
: whentrue
and the source image has anhttp
orhttps
scheme, set arel="canonical"
HTTP header to the value of the source image URL. More details here. Default:false
IMGPROXY_SO_REUSEPORT
: whentrue
, enablesSO_REUSEPORT
socket option (currently only available on Linux and macOS);IMGPROXY_PATH_PREFIX
: the URL path prefix. Example: when set to/abc/def
, the imgproxy URL will be/abc/def/%signature/%processing_options/%source_url
. Default: blankIMGPROXY_USER_AGENT
: the User-Agent header that will be sent with the source image request. Default:imgproxy/%current_version
IMGPROXY_USE_ETAG
: when set totrue
, enables using the ETag HTTP header for HTTP cache control. Default:false
IMGPROXY_ETAG_BUSTER
: change this to change ETags for all the images. Default: blankIMGPROXY_USE_LAST_MODIFIED
: when set totrue
, enables using the Last-Modified HTTP header for HTTP cache control. Default:false
IMGPROXY_CUSTOM_REQUEST_HEADERS
: pro list of custom headers that imgproxy will send while requesting the source image, divided by\;
(can be redefined byIMGPROXY_CUSTOM_HEADERS_SEPARATOR
). Example:X-MyHeader1=Lorem\;X-MyHeader2=Ipsum
IMGPROXY_CUSTOM_RESPONSE_HEADERS
: pro a list of custom response headers, separated by\;
(can be redefined byIMGPROXY_CUSTOM_HEADERS_SEPARATOR
). Example:X-MyHeader1=Lorem\;X-MyHeader2=Ipsum
IMGPROXY_CUSTOM_HEADERS_SEPARATOR
: pro a string that will be used as a custom header separator. Default:\;
IMGPROXY_REQUEST_HEADERS_PASSTHROUGH
: pro a list of names of incoming request headers that should be passed through to the source image request.IMGPROXY_RESPONSE_HEADERS_PASSTHROUGH
: pro a list of names of source image response headers that should be passed through to the imgproxy response.IMGPROXY_ENABLE_DEBUG_HEADERS
: when set totrue
, imgproxy will add debug headers to the response. Default:false
. The following headers will be added:X-Origin-Content-Length
: the size of the source imageX-Origin-Width
: the width of the source imageX-Origin-Height
: the height of the source imageX-Result-Width
: the width of the resultant imageX-Result-Height
: the height of the resultant image
IMGPROXY_SERVER_NAME
: pro theServer
header value. Default:imgproxy
Security
imgproxy protects you from so-called image bombs. Here's how you can specify the maximum image resolution which you consider reasonable:
-
IMGPROXY_MAX_SRC_RESOLUTION
: the maximum resolution of the source image, in megapixels. Images with larger actual size will be rejected. Default:50
warningWhen the source image is animated, imgproxy summarizes all its frames' resolutions while checking the source image resolution unless
IMGPROXY_MAX_ANIMATION_FRAME_RESOLUTION
is greater than zero. -
IMGPROXY_MAX_SRC_FILE_SIZE
: the maximum size of the source image, in bytes. Images with larger file size will be rejected. When set to0
, file size check is disabled. Default:0
imgproxy can process animated images (GIF, WebP), but since this operation is pretty memory heavy, only one frame is processed by default. You can increase the maximum animation frames that can be processed number of with the following variable:
IMGPROXY_MAX_ANIMATION_FRAMES
: the maximum number of animated image frames that may be processed. Default:1
IMGPROXY_MAX_ANIMATION_FRAME_RESOLUTION
: the maximum resolution of the animated source image frame, in megapixels. Images with larger actual frame size will be rejected. When set to0
, imgproxy will test the whole animated image resolution againstIMGPROXY_MAX_SRC_RESOLUTION
summarising all the frames' resolutions. Default:0
To check if the source image is SVG, imgproxy reads some amount of bytes; by default it reads a maximum of 32KB. However, you can change this value using the following variable:
IMGPROXY_MAX_SVG_CHECK_BYTES
: the maximum number of bytes imgproxy will read to recognize SVG files. If imgproxy is unable to recognize your SVG, try increasing this number. Default:32768
(32KB)
Requests to some image sources may go through too many redirects or enter an infinite loop. You can limit the number of allowed redirects:
IMGPROXY_MAX_REDIRECTS
: the max number of redirects imgproxy can follow while requesting the source image. When set to0
, no redirects are allowed. Default:10
You can also specify a secret key to enable authorization with the HTTP Authorization
header for use in production environments:
IMGPROXY_SECRET
: the authorization token. If specified, the HTTP request should contain theAuthorization: Bearer %secret%
header.
If you don't want to reveal your source URLs, you can encrypt them with the AES-CBC algorithm:
-
IMGPROXY_SOURCE_URL_ENCRYPTION_KEY
: hex-encoded key used for source URL encryption. Default: blanktipRead more about source URL encryption in the encrypting the source URL guide.
imgproxy does not send CORS headers by default. CORS will need to be allowed by using the following variable:
IMGPROXY_ALLOW_ORIGIN
: when specified, enables CORS headers with the provided origin. CORS headers are disabled by default.
You can limit allowed source URLs with the following variable:
-
IMGPROXY_ALLOWED_SOURCES
: a whitelist of source image URL prefixes divided by comma. Wildcards can be included with*
to match all characters except/
. When blank, imgproxy allows all source image URLs. Example:s3://,https://*.example.com/,local://
. Default: blankwarningBe careful when using this config to limit source URL hosts, and always add a trailing slash after the host.
Bad:
http://example.com
Good:
http://example.com/
If the trailing slash is absent,
http://example.com@baddomain.com
would be a permissable URL, however, the request would be made tobaddomain.com
. -
IMGPROXY_ALLOW_LOOPBACK_SOURCE_ADDRESSES
: whentrue
, allows connecting to loopback IP addresses (127.0.0.1
-127.255.255.255
and IPv6 analogues) when requesting source images. Default:false
-
IMGPROXY_ALLOW_LINK_LOCAL_SOURCE_ADDRESSES
: whentrue
, allows connecting to link-local multicast and unicast IP addresses (224.0.0.1
-224.0.0.255
,169.254.0.1
-169.254.255.255
, and IPv6 analogues) when requesting source images. Default:false
-
IMGPROXY_ALLOW_PRIVATE_SOURCE_ADDRESSES
: whentrue
, allows connecting to private IP addresses (10.0.0.0 - 10.255.255.255
,172.16.0.0 - 172.31.255.255
,192.168.0.0 - 192.168.255.255
, and IPv6 analogues) when requesting source images. Default:true
-
IMGPROXY_PNG_UNLIMITED
: whentrue
, disables the limit on the number of PNG chunks. Default:false
warningDisabling the limit on the number of PNG chunks can lead to memory exhaustion and DoS attacks.
-
IMGPROXY_SVG_UNLIMITED
: whentrue
, disables the limit on the SVG file size (10MB). Default:false
warningDisabling the limit on the SVG file size can lead to memory exhaustion and DoS attacks.
-
IMGPROXY_SANITIZE_SVG
: whentrue
, imgproxy will remove scripts from SVG images to prevent XSS attacks. Defaut:true
When using imgproxy in a development environment, it can be useful to ignore SSL verification:
IMGPROXY_IGNORE_SSL_VERIFICATION
: whentrue
, disables SSL verification, so imgproxy can be used in a development environment with self-signed SSL certificates.
Also you may want imgproxy to respond with the same error message that it writes to the log:
-
IMGPROXY_DEVELOPMENT_ERRORS_MODE
: whentrue
, imgproxy will respond with detailed error messages. Not recommended for production because some errors may contain stack traces. -
IMGPROXY_ALLOW_SECURITY_OPTIONS
: whentrue
, allows usage of security-related processing options such asmax_src_resolution
,max_src_file_size
,max_animation_frames
, andmax_animation_frame_resolution
. Default:false
.warningIMGPROXY_ALLOW_SECURITY_OPTIONS
allows bypassing your security restrictions. Don't set it totrue
unless you are completely sure that an attacker can't change your imgproxy URLs.
Cookies
imgproxy can pass cookies in image requests. This can be activated with IMGPROXY_COOKIE_PASSTHROUGH
. Unfortunately the Cookie
header doesn't contain information about which URLs these cookies are applicable to, so imgproxy can only assume (or must be told).
When cookie forwarding is activated, by default, imgproxy assumes the scope of the cookies to be all URLs with the same hostname/port and request scheme as given by the headers X-Forwarded-Host
, X-Forwarded-Port
, X-Forwarded-Scheme
or Host
. To change that use IMGPROXY_COOKIE_BASE_URL
.
-
IMGPROXY_COOKIE_PASSTHROUGH
: whentrue
, incoming cookies will be passed through the image request if they are applicable for the image URL. Default:false
-
IMGPROXY_COOKIE_BASE_URL
: when set, assume that cookies have the scope of this URL for an incoming request (instead of using request headers). If the cookies are applicable to the image URL too, they will be passed along in the image request.
Compression
IMGPROXY_QUALITY
: the default quality of the resultant image, percentage. Default:80
IMGPROXY_FORMAT_QUALITY
: default quality of the resulting image per format, separated by commas. Example:jpeg=70,avif=40,webp=60
. When a value for the resulting format is not set, theIMGPROXY_QUALITY
value is used. Default:avif=65
Advanced JPEG compression
IMGPROXY_JPEG_PROGRESSIVE
: whentrue
, enables progressive JPEG compression. Default:false
IMGPROXY_JPEG_NO_SUBSAMPLE
: pro whentrue
, chrominance subsampling is disabled. This will improve quality at the cost of larger file size. Default:false
IMGPROXY_JPEG_TRELLIS_QUANT
: pro whentrue
, enables trellis quantisation for each 8x8 block. Reduces file size but increases compression time. Default:false
IMGPROXY_JPEG_OVERSHOOT_DERINGING
: pro whentrue
, enables overshooting of samples with extreme values. Overshooting may reduce ringing artifacts from compression, in particular in areas where black text appears on a white background. Default:false
IMGPROXY_JPEG_OPTIMIZE_SCANS
: pro whentrue
, splits the spectrum of DCT coefficients into separate scans. Reduces file size but increases compression time. RequiresIMGPROXY_JPEG_PROGRESSIVE
to be true. Default:false
IMGPROXY_JPEG_QUANT_TABLE
: pro quantization table to use. Supported values are:0
: Table from JPEG Annex K (default)1
: Flat table2
: Table tuned for MSSIM on Kodak image set3
: Table from ImageMagick by N. Robidoux4
: Table tuned for PSNR-HVS-M on Kodak image set5
: Table from Relevance of Human Vision to JPEG-DCT Compression (1992)6
: Table from DCTune Perceptual Optimization of Compressed Dental X-Rays (1997)7
: Table from A Visual Detection Model for DCT Coefficient Quantization (1993)8
: Table from An Improved Detection Model for DCT Coefficient Quantization (1993)