Home

Awesome

Varnish Docker Container Image

Build Status Docker Pulls Docker Stars

Docker Images

❗For better reliability we release images with stability tags (wodby/varnish:6-X.X.X) which correspond to git tags. We strongly recommend using images only with stability tags.

Overview:

All images built for linux/amd64 and linux/arm64

Supported tags and respective Dockerfile links:

Environment Variables

VariableDefault ValueDescription
VARNISH_ALLOW_UNRESTRICTED_PURGEUsed for ban requests as well
VARNISH_BACKEND_BETWEEN_BYTES_TIMEOUT60s
VARNISH_BACKEND_CONNECT_TIMEOUT3.5s
VARNISH_BACKEND_FIRST_BYTE_TIMEOUT60s
VARNISH_BACKEND_GRACE2m
VARNISH_BACKEND_HOSTMandatory
VARNISH_BACKEND_PORT80
VARNISH_CACHE_PER_COUNTRYSeparate caches based on country code
VARNISH_CACHE_PER_CURRENCYSeparate caches based on currency
VARNISH_CURRENCY_EUR_COUNTRY_CODESSee currencies
VARNISH_CURRENCY_USD_COUNTRY_CODESSee currencies
VARNISH_BIG_FILES_SIZE1048576010MB
VARNISH_BIG_FILES_TTL120s
VARNISH_CACHE_STATIC_FILES
VARNISH_CONFIG_PRESET
VARNISH_DEFAULT_TTL120s
VARNISH_ERRORS_GRACE15s
VARNISH_PURGE_EXTERNAL_REQUEST_HEADER
VARNISH_KEEP_ALL_COOKIES
VARNISH_KEEP_ALL_PARAMS
VARNISH_IMPORT_MODULESSeparated by comma
VARNISH_MOBILE_DISABLE_CASH
VARNISH_MOBILE_SEPARATE_CASH
VARNISH_MOBILE_USER_AGENTSee default value below
VARNISH_PIPE_CLOSE_CONNECTION
VARNISH_PURGE_KEYRandomly generated if missing
VARNISH_SECONDARY_STORAGE_CONDITIONMust be valid VCL
VARNISH_SECRETGenerated automatically if missing
VARNISH_STATIC_FILESSee default value below
VARNISH_STATIC_TTL86400In seconds
VARNISH_STRIP_COOKIESSee default value below
VARNISH_STRIP_PARAMSSee default value below
VARNISH_STRIP_ALL_PARAMSIgnored if $VARNISH_KEEP_ALL_PARAMS is set
VARNISH_PAGESPEED_SECRET_KEYShould be used if mod_pagespeed is enabled
VARNISHD_DEFAULT_TTL120
VARNISHD_MEMORY_SIZE64m
VARNISHD_PARAM_BAN_LURKER_AGE60.000
VARNISHD_PARAM_BAN_LURKER_BATCH1000
VARNISHD_PARAM_BAN_LURKER_SLEEP0.010
VARNISHD_PARAM_BETWEEN_BYTES_TIMEOUT60.000
VARNISHD_PARAM_CONNECT_TIMEOUT3.500
VARNISHD_PARAM_DEFAULT_GRACE10.000
VARNISHD_PARAM_DEFAULT_KEEP0.000
VARNISHD_PARAM_DEFAULT_TTL120.000
VARNISHD_PARAM_FETCH_CHUNKSIZE16k
VARNISHD_PARAM_FIRST_BYTE_TIMEOUT60.000
VARNISHD_PARAM_GZIP_BUFFER32k
VARNISHD_PARAM_GZIP_LEVEL6
VARNISHD_PARAM_GZIP_MEMLEVEL8
VARNISHD_PARAM_HTTP_GZIP_SUPPORTon
VARNISHD_PARAM_HTTP_MAX_HDR64
VARNISHD_PARAM_HTTP_REQ_HDR_LEN8k
VARNISHD_PARAM_HTTP_REQ_SIZE32k
VARNISHD_PARAM_HTTP_RESP_HDR_LEN8k
VARNISHD_PARAM_HTTP_RESP_SIZE32k
VARNISHD_PARAM_IDLE_SEND_TIMEOUT60.000
VARNISHD_PARAM_MAX_ESI_DEPTH5
VARNISHD_PARAM_MAX_RESTARTS4
VARNISHD_PARAM_MAX_RETRIES4
VARNISHD_PARAM_NUKE_LIMIT50
VARNISHD_PARAM_PING_INTERVAL3
VARNISHD_PARAM_PIPE_TIMEOUT60.000
VARNISHD_PARAM_POOL_REQ10,100,10
VARNISHD_PARAM_POOL_SESS10,100,10
VARNISHD_PARAM_PREFER_IPV6off
VARNISHD_PARAM_RUSH_EXPONENT3
VARNISHD_PARAM_SEND_TIMEOUT600
VARNISHD_PARAM_SHORTLIVED10.000
VARNISHD_PARAM_TCP_KEEPALIVE_INTVL75.000
VARNISHD_PARAM_TCP_KEEPALIVE_PROBES8
VARNISHD_PARAM_TCP_KEEPALIVE_TIME7200.000
VARNISHD_PARAM_THREAD_POOL_ADD_DELAY0.000
VARNISHD_PARAM_THREAD_POOL_DESTROY_DELAY1.000
VARNISHD_PARAM_THREAD_POOL_FAIL_DELAY0.200
VARNISHD_PARAM_THREAD_POOL_MAX5000
VARNISHD_PARAM_THREAD_POOL_MIN100
VARNISHD_PARAM_THREAD_POOL_STACK48k
VARNISHD_PARAM_THREAD_POOL_TIMEOUT300.000
VARNISHD_PARAM_THREAD_POOLS2
VARNISHD_PARAM_THREAD_QUEUE_LIMIT20
VARNISHD_PARAM_TIMEOUT_IDLE5.000
VARNISHD_PARAM_TIMEOUT_LINGER0.050
VARNISHD_PARAM_VSL_BUFFER4k
VARNISHD_PARAM_VSL_RECLEN255b
VARNISHD_PARAM_VSL_SPACE80M
VARNISHD_PARAM_VSM_SPACE1M
VARNISHD_PARAM_WORKSPACE_BACKEND64k
VARNISHD_PARAM_WORKSPACE_CLIENT64k
VARNISHD_PARAM_WORKSPACE_SESSION0.50k
VARNISHD_PARAM_WORKSPACE_THREAD2k
VARNISHD_SECONDARY_STORAGESee example below
VARNISHD_SECRET_FILE/etc/varnish/secret
VARNISHD_VCL_SCRIPT/etc/varnish/default.vcl
VARNISH_MOBILE_USER_AGENT:

Backslashes must be escaped as \\

ipod|android|blackberry|phone|mobile|kindle|silk|fennec|tablet|webos|palm|windows ce|nokia|philips|samsung|sanyo|sony|panasonic|ericsson|alcatel|series60|series40|opera mini|opera mobi|au-mic|audiovox|avantgo|blazer|danger|docomo|epoc|ericy|i-mode|ipaq|midp-|mot-|netfront|nitro|pocket|portalmmm|rover|sie-|symbian|cldc-|j2me|up\\.browser|up\\.link|vodafone|wap1\\.|wap2\\.
VARNISH_STATIC_FILES:
asc|doc|xls|ppt|csv|svg|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|webp
VARNISH_STRIP_COOKIES

Ignored if $VARNISH_KEEP_ALL_COOKIES is set

__[a-z]+|wooTracker|VCKEY-[a-zA-Z0-9-_]+
VARNISH_STRIP_PARAMS

Ignored if $VARNISH_KEEP_ALL_PARAMS is set

utm_[a-z]+|gclid|cx|ie|cof|siteurl|fbclid
VARNISH_SECONDARY_STORAGE_CONDITION:

Allows defining custom conditions for storing the cache object in the secondary storage; as it is injected into an if it has to contain valid VCL syntax for it.

Please note that VARNISHD_SECONDARY_STORAGE must be defined as well, otherwise the secondary storage would not be available.

Example: instruct varnish to store in the secondary storage from the backend via custom header X-Cache-Bin:

VARNISH_STORAGE_CONDITION='beresp.http.x-cache-bin = "secondary"'

Installed Modules

ModuleVersionImported
geoip1.0.3
digest1.0.2
cookielatest
vsthrottlelatest
headerlatest
saintmodelatest
softpurgelatest
tcplatest
varlatest
xkeylatest
bodyaccesslatest

Modules can be imported as $VARNISH_IMPORT_MODULES=xkey,softpurge.

Default Behaviour

Caching Rules

Cache Personification

White-listed cookies starting with VCKEY- followed by alphanumeric characters, underscores or hyphens are used to build cache hash. You can use such cookies to personify cache by a certain criteria, e.g. set VCKEY-lang to en or fr to cache different versions for English and French users.

On your backend you should check whether VCKEY- cookie exists, if it does generate a personified version of a page and do not set cookie again, otherwise it won't be cached on Varnish.

GeoIP

We identify client's two-letter country code (ISO 3166) and pass it to a backend in X-Country-Code header. If Varnish could not recognize the country the default value will be Unknown. You can optionally uniquify cache per country by setting $VARNISH_CACHE_PER_COUNTRY=1. We use GeoLite database from MaxMind.

If we see CloudFlare country code header we use it instead.

Currency

We use the country code to identify the currency and pass it to a backend in X-Currency header. You can optionally uniquify cache per currency by setting $VARNISH_CACHE_PER_CURRENCY=1.

We use data from IBAN to identify which country uses which currency, currently only USD and EUR supported.

Country codes for USD ($VARNISH_CURRENCY_USD_COUNTRY_CODES):

US|AS|BQ|IO|EC|SV|GU|HT|MH|FM|MP|PA|PW|PR|TL|TC|UM|VG|VI

Country codes for EUR ($VARNISH_CURRENCY_EUR_COUNTRY_CODES):

AD|AT|BE|CY|EE|FI|FR|GF|TF|DE|GP|GR|VA|IE|IT|LV|LT|LU|MT|MQ|YT|MC|ME|NL|PT|RE|BL|MF|PM|SM|SK|SI|ES|CE|CH|AX

Cache Flushing

Miscellaneous

Config Presets

You can use one of the following config presets to extend the default behaviour:

Drupal

Add VARNISH_CONFIG_PRESET=drupal to use this preset.

VARNISH_DRUPAL_EXCLUDE_URLS:

Backslashes must be escaped as \\

^(/update\\.php|/([a-z]{2}/)?admin|/([a-z]{2}/)?admin/.*|/([a-z]{2}/)?system/files/.*|/([a-z]{2}/)?flag/.*|.*/ajax/.*|.*/ahah/.*)$
VARNISH_DRUPAL_PRESERVED_COOKIES:

Not affected by $VARNISH_KEEP_ALL_COOKIES

SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE

WordPress

Add VARNISH_CONFIG_PRESET=wordpress to use this preset.

VARNISH_WP_PRESERVED_COOKIES:

Not affected by $VARNISH_KEEP_ALL_COOKIES

PHPSESSID|wp-postpass_[a-z0-9]+|wordpress_[_a-z0-9]+|wordpress_logged_in_[a-z0-9]+|woocommerce_cart_hash|woocommerce_items_in_cart|wp_woocommerce_session_[a-z0-9]+|akm_mobile

PageSpeed Downstream Caching

This image contains implementation for modpagespeed downstream caching as described at https://www.modpagespeed.com/doc/downstream-caching. You can enable this behavior by specifying $VARNISH_PAGESPEED_SECRET_KEY to the value that matches DownstreamCacheRebeaconingKey in your Nginx/Apache config. This value will be used as PS-ShouldBeacon for 5% of hits and 25% of misses. Also, when static files cache enabled on Varnish, PS-CapabilityList will be set to fully general optimizations only to unify behavior for all browsers.

Orchestration Actions

make COMMAND [params ...]

commands:
    check-ready [host max_try wait_seconds delay_seconds]
    flush [host]
 
default params values:
    host localhost
    max_try 1
    wait_seconds 1
    delay_seconds 0

Deployment

Deploy Varnish container to your own server via Wodby Wodby.