I have a varnish 4 in front of an Apache web server. All is good, except i have some random 502 errors.
What is strange is that there is nothing in the varnishlog file for this error ! (all others requests are logged)
My parameters : VARNISH_MIN_THREADS=50 VARNISH_MAX_THREADS=1000 VARNISH_THREAD_TIMEOUT=120
What i can do in order to fix this ?
My default.vcl :
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8055";
}
backend php53 {
.host = "127.0.0.1";
.port = "8053";
}
sub vcl_recv {
# Compatiblity with Apache log
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For = client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
if (
req.http.Host ~ "site1" ||
req.http.Host ~ "site2")
{
set req.backend_hint = php53;
}
if (req.http.Host ~ "mainsite" ){
if (req.method == "POST") {
return (pipe);
}
if (req.method == "GET" && (req.url ~ "^/admin")) {
return (pass);
}
}
if (req.method != "GET" && req.method != "HEAD")
{
return (pass);
}
if (req.url ~ "(?i)\.(jpeg|jpg|png|gif|ico)$") {
unset req.http.Cookie;
return (hash);
} else {
return (pass);
}
}
sub vcl_backend_response {
if (beresp.http.Content-Length !~ "[0-9]{7,10}") {
return(deliver);
}
}
i have 502 errors on 'mainsite' (prestashop ecommerce, with lot of images)
My current stat :
MAIN.uptime 151353 1.00 Child process uptime MAIN.sess_conn 59309 0.39 Sessions accepted
MAIN.sess_drop 0 0.00 Sessions dropped
MAIN.sess_fail 0 0.00 Session accept failures
MAIN.backend_conn 24076 0.16 Backend conn. success
MAIN.backend_unhealthy 0 0.00 Backend conn. not attempted
MAIN.backend_busy 0 0.00 Backend conn. too many
MAIN.backend_fail 85 0.00 Backend conn. failures
MAIN.backend_reuse 53606 0.35 Backend conn. reuses
MAIN.backend_toolate 11249 0.07 Backend conn. was closed
MAIN.backend_recycle 64856 0.43 Backend conn. recycles
MAIN.backend_retry 0 0.00 Backend conn. retry
MAIN.threads 100 . Total number of threads
MAIN.threads_created 108 0.00 Threads created
MAIN.threads_destroyed 8 0.00 Threads destoryed
MAIN.threads_failed 0 0.00 Thread creation failed
MAIN.busy_sleep 3 0.00 Number of requests sent to sleep on busy objhdr
MAIN.busy_wakeup 3 0.00 Number of requests woken after sleep on busy objhdr
MAIN.sess_queued 11 0.00 Sessions queued for thread
ps aux | grep -i varnish | grep -v grep :
root 22319 0.0 0.5 121896 84060 ? SLs 12:21 0:00 /usr/sbin/varnishd -P /var/run/varnish.pid -a :80 -f /etc/varnish/default.vcl -T 127.0.0.1:6082 -t 120 -p thread_pool_min=50 -p thread_pool_max=1000 -p thread_pool_timeout=120 -u varnish -g varnish -S /etc/varnish/secret -s malloc,1G
varnish 22321 0.4 0.5 321348 92604 ? Sl 12:21 0:00 /usr/sbin/varnishd -P /var/run/varnish.pid -a :80 -f /etc/varnish/default.vcl -T 127.0.0.1:6082 -t 120 -p thread_pool_min=50 -p thread_pool_max=1000 -p thread_pool_timeout=120 -u varnish -g varnish -S /etc/varnish/secret -s malloc,1G
have you looked into apache error log for "mainsite" ?
paste output of :
And see if your malloc size is not big to serve big contents size
Try:
beresp.http.Content-Length !~ "keep this size small"
(if that is the case) Note: change that to regex to meet ur requirement where it says keep this size smalland check if you still get that error,