Varnish doesn't seems to be doing anything Announcing the arrival of Valued Associate #679:...

What would be the ideal power source for a cybernetic eye?

Coloring maths inside a tcolorbox

51k Euros annually for a family of 4 in Berlin: Is it enough?

Is the Standard Deduction better than Itemized when both are the same amount?

Storing hydrofluoric acid before the invention of plastics

Is it true that "carbohydrates are of no use for the basal metabolic need"?

What to do with chalk when deepwater soloing?

How discoverable are IPv6 addresses and AAAA names by potential attackers?

Is pollution the main cause of Notre Dame Cathedral's deterioration?

What's the meaning of 間時肆拾貳 at a car parking sign

Are two submodules (where one is contained in the other) isomorphic if their quotientmodules are isomorphic?

Resolving to minmaj7

How come Sam didn't become Lord of Horn Hill?

porting install scripts : can rpm replace apt?

Short Story with Cinderella as a Voo-doo Witch

What causes the vertical darker bands in my photo?

Apollo command module space walk?

Why didn't this character "real die" when they blew their stack out in Altered Carbon?

Why did the IBM 650 use bi-quinary?

Identify plant with long narrow paired leaves and reddish stems

How can I make names more distinctive without making them longer?

What exactly is a "Meth" in Altered Carbon?

ListPlot join points by nearest neighbor rather than order

3 doors, three guards, one stone



Varnish doesn't seems to be doing anything



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Come Celebrate our 10 Year Anniversary!Varnish doesn't seem to be cachingConfigure php5-fpm for many concurrent usersVarnish only cache assets from single sessionsub vcl_recv | Magento + VarnishVCL - configuration for Magento and Varnish 3.0.2Avoiding Varnish Hitting Magento Cookies - VCLVarnish not loading anything in “images” folderVarnish doesn't cache anything: varnishstat always with 0 ratio“service varnish stop” doesn't actually stop VarnishVarnish Cache - Cache Only Seems warmed on each browser





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I would highly appreciate an input on whats going wrong here:



Running Magento on Ubuntu 14.04 x64 + Nginx + Mysql + Php5-FPM



Please double check my steps so maybe you could help me point what's messy:




  • Installed Varnish

  • Installed Magento Tupertine (an extension that makes Varnish work with Magento) from http://www.magentocommerce.com/magento-connect/turpentine-varnish-cache.html


  • Set the required configurations on Magento backend, important info bellow:



    Server List: 127.0.0.1:6082
    Backend Host: 127.0.0.1
    Backend Port: 8081




Varnish is running on 8081 and Nginx on 8080.



My /etc/varnish/default.vcl conf:



C{
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
static pthread_mutex_t lrand_mutex = PTHREAD_MUTEX_INITIALIZER;
void generate_uuid(char* buf) {
pthread_mutex_lock(&lrand_mutex);
long a = lrand48();
long b = lrand48();
long c = lrand48();
long d = lrand48();
pthread_mutex_unlock(&lrand_mutex);
// SID must match this regex for Kount compat /^w{1,32}$/
sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx",
a,
b & 0xffff,
(b & ((long)0x0fff0000) >> 16) | 0x4000,
(c & 0x0fff) | 0x8000,
(c & (long)0xffff0000) >> 16,
d
);
return;
}
}C
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 300s;
.between_bytes_timeout = 300s;
}
backend admin {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 21600s;
.between_bytes_timeout = 21600s;
}
acl crawler_acl {
"127.0.0.1";
}
acl debug_acl {
}
sub generate_session {
if (req.url ~ ".*[&?]SID=([^&]+).*") {
set req.http.X-Varnish-Faked-Session = regsub(
req.url, ".*[&?]SID=([^&]+).*", "frontend=1");
} else {
C{
char uuid_buf [50];
generate_uuid(uuid_buf);
VRT_SetHdr(sp, HDR_REQ,
"30X-Varnish-Faked-Session:",
uuid_buf,
vrt_magic_string_end
);
}C
}
if (req.http.Cookie) {
std.collect(req.http.Cookie);
set req.http.Cookie = req.http.X-Varnish-Faked-Session +
"; " + req.http.Cookie;
} else {
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
}
}
sub generate_session_expires {
C{
time_t now = time(NULL);
struct tm now_tm = *gmtime(&now);
now_tm.tm_sec += 86400;
mktime(&now_tm);
char date_buf [50];
strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm);
VRT_SetHdr(sp, HDR_RESP,
"31X-Varnish-Cookie-Expires:",
date_buf,
vrt_magic_string_end
);
}C
}
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (!false || req.http.Authorization ||
req.request !~ "^(GET|HEAD)$" ||
req.http.Cookie ~ "varnish_bypass=1") {
return (pipe);
}
set req.url = regsuball(req.url, "(.*)//+(.*)", "1/2");
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
set req.http.X-Turpentine-Secret-Handshake = "1";
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?admin") {
set req.backend = admin;
return (pipe);
}
if (req.http.Cookie ~ "bcurrency=") {
set req.http.X-Varnish-Currency = regsub(
req.http.Cookie, ".*bcurrency=([^;]*).*", "1");
}
if (req.http.Cookie ~ "bstore=") {
set req.http.X-Varnish-Store = regsub(
req.http.Cookie, ".*bstore=([^;]*).*", "1");
}
if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") {
set req.http.X-Varnish-Esi-Method = regsub(
req.url, ".*/method/(w+)/.*", "1");
set req.http.X-Varnish-Esi-Access = regsub(
req.url, ".*/access/(w+)/.*", "1");
if (req.http.X-Varnish-Esi-Method == "esi" && req.esi_level == 0 &&
!(false || client.ip ~ debug_acl)) {
error 403 "External ESI requests are not allowed";
}
}
if (req.http.Cookie !~ "frontend=") {
if (client.ip ~ crawler_acl ||
req.http.User-Agent ~ "^(?:ApacheBench/.*|.*Googlebot.*|JoeDog/.*Siege.*|magespeedtest.com|Nexcessnet_Turpentine/.*)$") {
set req.http.Cookie = "frontend=crawler-session";
} else {
call generate_session;
}
}
if (true &&
req.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
unset req.http.Cookie;
unset req.http.X-Varnish-Faked-Session;
return (lookup);
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?(?:admin|api|cron.php)" ||
req.url ~ "?.*__from_store=") {
return (pipe);
}
if (true &&
req.url ~ "(?:[?&](?:__SID|XDEBUG_PROFILE)(?=[&=]|$))") {
return (pass);
}
if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") {
set req.url = regsuball(req.url, "(?:(?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "1");
set req.url = regsuball(req.url, "(?:(?)&|?$)", "1");
}
return (lookup);
}
}
sub vcl_pipe {
unset bereq.http.X-Turpentine-Secret-Handshake;
set bereq.http.Connection = "close";
}
sub vcl_hash {
hash_data(req.url);
if (req.http.Host) {
hash_data(req.http.Host);
} else {
hash_data(server.ip);
}
hash_data(req.http.Ssl-Offloaded);
if (req.http.X-Normalized-User-Agent) {
hash_data(req.http.X-Normalized-User-Agent);
}
if (req.http.Accept-Encoding) {
hash_data(req.http.Accept-Encoding);
}
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
}
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "1"));
}
return (hash);
}
sub vcl_hit {
}
sub vcl_fetch {
set req.grace = 15s;
set beresp.http.X-Varnish-Host = req.http.host;
set beresp.http.X-Varnish-URL = req.url;
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
unset beresp.http.Vary;
set beresp.do_gzip = true;
if (beresp.status != 200 && beresp.status != 404) {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (beresp.http.Set-Cookie) {
set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie;
unset beresp.http.Set-Cookie;
}
unset beresp.http.Cache-Control;
unset beresp.http.Expires;
unset beresp.http.Pragma;
unset beresp.http.Cache;
unset beresp.http.Age;
if (beresp.http.X-Turpentine-Esi == "1") {
set beresp.do_esi = true;
}
if (beresp.http.X-Turpentine-Cache == "0") {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (true &&
bereq.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
set beresp.ttl = 28800s;
set beresp.http.Cache-Control = "max-age=28800";
} elseif (req.http.X-Varnish-Esi-Method) {
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
set beresp.http.X-Varnish-Session = regsub(req.http.Cookie,
"^.*?frontend=([^;]*);*.*$", "1");
}
if (req.http.X-Varnish-Esi-Method == "ajax" &&
req.http.X-Varnish-Esi-Access == "public") {
set beresp.http.Cache-Control = "max-age=" + regsub(
req.url, ".*/ttl/(d+)/.*", "1");
}
set beresp.ttl = std.duration(
regsub(
req.url, ".*/ttl/(d+)/.*", "1s"),
300s);
if (beresp.ttl == 0s) {
set beresp.ttl = 15s;
return (hit_for_pass);
}
} else {
set beresp.ttl = 3600s;
}
}
}
return (deliver);
}
}
sub vcl_deliver {
if (req.http.X-Varnish-Faked-Session) {
call generate_session_expires;
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
if (req.http.Host) {
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + regsub(req.http.Host, ":d+$", "");
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
unset resp.http.X-Varnish-Cookie-Expires;
}
if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") {
set resp.http.Cache-Control = "no-cache";
}
if (true || client.ip ~ debug_acl) {
set resp.http.X-Varnish-Hits = obj.hits;
set resp.http.X-Varnish-Esi-Method = req.http.X-Varnish-Esi-Method;
set resp.http.X-Varnish-Esi-Access = req.http.X-Varnish-Esi-Access;
set resp.http.X-Varnish-Currency = req.http.X-Varnish-Currency;
set resp.http.X-Varnish-Store = req.http.X-Varnish-Store;
} else {
#unset resp.http.X-Varnish;
unset resp.http.Via;
unset resp.http.X-Powered-By;
unset resp.http.Server;
unset resp.http.X-Turpentine-Cache;
unset resp.http.X-Turpentine-Esi;
unset resp.http.X-Turpentine-Flush-Events;
unset resp.http.X-Turpentine-Block;
unset resp.http.X-Varnish-Session;
unset resp.http.X-Varnish-Host;
unset resp.http.X-Varnish-URL;
unset resp.http.X-Varnish-Set-Cookie;
}
}


My /etc/default/varnish conf:



# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#

# Should we start varnishd at boot? Set to "no" to disable.
START=yes

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Maximum locked memory size (for ulimit -l)
# Used for locking the shared memory log in memory. If you increase log size,
# you need to increase this number as well
MEMLOCK=82000

# Default varnish instance name is the local nodename. Can be overridden with
# the -n switch, to have more instances on a single server.
# INSTANCE=$(uname -n)

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a 1GB fixed-size cache file.
#
# DAEMON_OPTS="-a :6081
# -T localhost:6082
# -b localhost:8080
# -u varnish -g varnish
# -S /etc/varnish/secret
# -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"


## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a 1GB
# fixed-size cache file.
#
DAEMON_OPTS="-a :8081
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-s malloc,256m
-p esi_syntax=0x2
-p cli_buffer=16384"


## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
# VARNISH_VCL_CONF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
# VARNISH_LISTEN_PORT=6081
#
# # Telnet admin interface listen address and port
# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
# VARNISH_ADMIN_LISTEN_PORT=6082
#
# # The minimum number of worker threads to start
# VARNISH_MIN_THREADS=1
#
# # The Maximum number of worker threads to start
# VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
# VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
# VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
# VARNISH_STORAGE_SIZE=1G
#
# # File containing administration secret
# VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # Backend storage specification
# VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
# VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT}
# -f ${VARNISH_VCL_CONF}
# -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT}
# -t ${VARNISH_TTL}
# -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT}
# -S ${VARNISH_SECRET_FILE}
# -s ${VARNISH_STORAGE}"
#


## Alternative 4, Do It Yourself
#
# DAEMON_OPTS=""


My /etc/nginx/sites-available/site conf:



server {
listen 80;
server_name royalpets.com.br *.royalpets.com.br;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_buffer_size 8k;
proxy_set_header Host $host;
}
}

server {
listen 80;
server_name acp.royalpets.com.br;
root /var/www/acp;
index index.php index.html index.htm;

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

}
server {
listen 8080;

#server_name royalpets.com.br; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/www/magento;

location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

client_max_body_size 10m;
}


Website header (no X-Varnish showing up):



GET / HTTP/1.1
Host: royalpets.com.br
Accept: image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2,es;q=0.2,gl;q=0.2,pl;q=0.2,ja;q=0.2
Referer: https://www.facebook.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Thu, 07 Aug 2014 17:27:44 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: nginx/1.6.0
Set-Cookie: frontend=uosmrugp8cnti8v0pqo564tbj0; expires=Fri, 08-Aug-2014 17:27:42 GMT; path=/; domain=royalpets.com.br; httponly
Transfer-Encoding: chunked
X-Powered-By: PHP/5.3.10-1ubuntu3.13


No errors on the extension page, horrible site speed (8s+), what am I doing wrong?










share|improve this question














bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Where's that varnish config from?

    – Shane Madden
    Aug 7 '14 at 17:51











  • @ShaneMadden it's generated from the module's backend pressing a button, it asks me to download it and upload to /etc/varnish/.

    – Bruno Dombidau
    Aug 7 '14 at 17:55











  • Hmm, I wish they generated with with decent tabbing :( Let's see what it's doing with the requests, run varnishlog and see what the output is when making one of the slow requests?

    – Shane Madden
    Aug 7 '14 at 17:59











  • Shouldn't Magento connect to nginx and nginx connect to Varnish? It appears above as tho you are directing Magento to Varnish directly; but I may not be interpreting the configs accurately.

    – ericx
    Aug 7 '14 at 17:59











  • @ShaneMadden How am I supposed to do that with 10+ online users? I know it's dumb to test it live but it's all I got.

    – Bruno Dombidau
    Aug 7 '14 at 18:16


















1















I would highly appreciate an input on whats going wrong here:



Running Magento on Ubuntu 14.04 x64 + Nginx + Mysql + Php5-FPM



Please double check my steps so maybe you could help me point what's messy:




  • Installed Varnish

  • Installed Magento Tupertine (an extension that makes Varnish work with Magento) from http://www.magentocommerce.com/magento-connect/turpentine-varnish-cache.html


  • Set the required configurations on Magento backend, important info bellow:



    Server List: 127.0.0.1:6082
    Backend Host: 127.0.0.1
    Backend Port: 8081




Varnish is running on 8081 and Nginx on 8080.



My /etc/varnish/default.vcl conf:



C{
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
static pthread_mutex_t lrand_mutex = PTHREAD_MUTEX_INITIALIZER;
void generate_uuid(char* buf) {
pthread_mutex_lock(&lrand_mutex);
long a = lrand48();
long b = lrand48();
long c = lrand48();
long d = lrand48();
pthread_mutex_unlock(&lrand_mutex);
// SID must match this regex for Kount compat /^w{1,32}$/
sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx",
a,
b & 0xffff,
(b & ((long)0x0fff0000) >> 16) | 0x4000,
(c & 0x0fff) | 0x8000,
(c & (long)0xffff0000) >> 16,
d
);
return;
}
}C
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 300s;
.between_bytes_timeout = 300s;
}
backend admin {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 21600s;
.between_bytes_timeout = 21600s;
}
acl crawler_acl {
"127.0.0.1";
}
acl debug_acl {
}
sub generate_session {
if (req.url ~ ".*[&?]SID=([^&]+).*") {
set req.http.X-Varnish-Faked-Session = regsub(
req.url, ".*[&?]SID=([^&]+).*", "frontend=1");
} else {
C{
char uuid_buf [50];
generate_uuid(uuid_buf);
VRT_SetHdr(sp, HDR_REQ,
"30X-Varnish-Faked-Session:",
uuid_buf,
vrt_magic_string_end
);
}C
}
if (req.http.Cookie) {
std.collect(req.http.Cookie);
set req.http.Cookie = req.http.X-Varnish-Faked-Session +
"; " + req.http.Cookie;
} else {
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
}
}
sub generate_session_expires {
C{
time_t now = time(NULL);
struct tm now_tm = *gmtime(&now);
now_tm.tm_sec += 86400;
mktime(&now_tm);
char date_buf [50];
strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm);
VRT_SetHdr(sp, HDR_RESP,
"31X-Varnish-Cookie-Expires:",
date_buf,
vrt_magic_string_end
);
}C
}
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (!false || req.http.Authorization ||
req.request !~ "^(GET|HEAD)$" ||
req.http.Cookie ~ "varnish_bypass=1") {
return (pipe);
}
set req.url = regsuball(req.url, "(.*)//+(.*)", "1/2");
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
set req.http.X-Turpentine-Secret-Handshake = "1";
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?admin") {
set req.backend = admin;
return (pipe);
}
if (req.http.Cookie ~ "bcurrency=") {
set req.http.X-Varnish-Currency = regsub(
req.http.Cookie, ".*bcurrency=([^;]*).*", "1");
}
if (req.http.Cookie ~ "bstore=") {
set req.http.X-Varnish-Store = regsub(
req.http.Cookie, ".*bstore=([^;]*).*", "1");
}
if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") {
set req.http.X-Varnish-Esi-Method = regsub(
req.url, ".*/method/(w+)/.*", "1");
set req.http.X-Varnish-Esi-Access = regsub(
req.url, ".*/access/(w+)/.*", "1");
if (req.http.X-Varnish-Esi-Method == "esi" && req.esi_level == 0 &&
!(false || client.ip ~ debug_acl)) {
error 403 "External ESI requests are not allowed";
}
}
if (req.http.Cookie !~ "frontend=") {
if (client.ip ~ crawler_acl ||
req.http.User-Agent ~ "^(?:ApacheBench/.*|.*Googlebot.*|JoeDog/.*Siege.*|magespeedtest.com|Nexcessnet_Turpentine/.*)$") {
set req.http.Cookie = "frontend=crawler-session";
} else {
call generate_session;
}
}
if (true &&
req.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
unset req.http.Cookie;
unset req.http.X-Varnish-Faked-Session;
return (lookup);
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?(?:admin|api|cron.php)" ||
req.url ~ "?.*__from_store=") {
return (pipe);
}
if (true &&
req.url ~ "(?:[?&](?:__SID|XDEBUG_PROFILE)(?=[&=]|$))") {
return (pass);
}
if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") {
set req.url = regsuball(req.url, "(?:(?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "1");
set req.url = regsuball(req.url, "(?:(?)&|?$)", "1");
}
return (lookup);
}
}
sub vcl_pipe {
unset bereq.http.X-Turpentine-Secret-Handshake;
set bereq.http.Connection = "close";
}
sub vcl_hash {
hash_data(req.url);
if (req.http.Host) {
hash_data(req.http.Host);
} else {
hash_data(server.ip);
}
hash_data(req.http.Ssl-Offloaded);
if (req.http.X-Normalized-User-Agent) {
hash_data(req.http.X-Normalized-User-Agent);
}
if (req.http.Accept-Encoding) {
hash_data(req.http.Accept-Encoding);
}
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
}
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "1"));
}
return (hash);
}
sub vcl_hit {
}
sub vcl_fetch {
set req.grace = 15s;
set beresp.http.X-Varnish-Host = req.http.host;
set beresp.http.X-Varnish-URL = req.url;
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
unset beresp.http.Vary;
set beresp.do_gzip = true;
if (beresp.status != 200 && beresp.status != 404) {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (beresp.http.Set-Cookie) {
set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie;
unset beresp.http.Set-Cookie;
}
unset beresp.http.Cache-Control;
unset beresp.http.Expires;
unset beresp.http.Pragma;
unset beresp.http.Cache;
unset beresp.http.Age;
if (beresp.http.X-Turpentine-Esi == "1") {
set beresp.do_esi = true;
}
if (beresp.http.X-Turpentine-Cache == "0") {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (true &&
bereq.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
set beresp.ttl = 28800s;
set beresp.http.Cache-Control = "max-age=28800";
} elseif (req.http.X-Varnish-Esi-Method) {
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
set beresp.http.X-Varnish-Session = regsub(req.http.Cookie,
"^.*?frontend=([^;]*);*.*$", "1");
}
if (req.http.X-Varnish-Esi-Method == "ajax" &&
req.http.X-Varnish-Esi-Access == "public") {
set beresp.http.Cache-Control = "max-age=" + regsub(
req.url, ".*/ttl/(d+)/.*", "1");
}
set beresp.ttl = std.duration(
regsub(
req.url, ".*/ttl/(d+)/.*", "1s"),
300s);
if (beresp.ttl == 0s) {
set beresp.ttl = 15s;
return (hit_for_pass);
}
} else {
set beresp.ttl = 3600s;
}
}
}
return (deliver);
}
}
sub vcl_deliver {
if (req.http.X-Varnish-Faked-Session) {
call generate_session_expires;
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
if (req.http.Host) {
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + regsub(req.http.Host, ":d+$", "");
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
unset resp.http.X-Varnish-Cookie-Expires;
}
if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") {
set resp.http.Cache-Control = "no-cache";
}
if (true || client.ip ~ debug_acl) {
set resp.http.X-Varnish-Hits = obj.hits;
set resp.http.X-Varnish-Esi-Method = req.http.X-Varnish-Esi-Method;
set resp.http.X-Varnish-Esi-Access = req.http.X-Varnish-Esi-Access;
set resp.http.X-Varnish-Currency = req.http.X-Varnish-Currency;
set resp.http.X-Varnish-Store = req.http.X-Varnish-Store;
} else {
#unset resp.http.X-Varnish;
unset resp.http.Via;
unset resp.http.X-Powered-By;
unset resp.http.Server;
unset resp.http.X-Turpentine-Cache;
unset resp.http.X-Turpentine-Esi;
unset resp.http.X-Turpentine-Flush-Events;
unset resp.http.X-Turpentine-Block;
unset resp.http.X-Varnish-Session;
unset resp.http.X-Varnish-Host;
unset resp.http.X-Varnish-URL;
unset resp.http.X-Varnish-Set-Cookie;
}
}


My /etc/default/varnish conf:



# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#

# Should we start varnishd at boot? Set to "no" to disable.
START=yes

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Maximum locked memory size (for ulimit -l)
# Used for locking the shared memory log in memory. If you increase log size,
# you need to increase this number as well
MEMLOCK=82000

# Default varnish instance name is the local nodename. Can be overridden with
# the -n switch, to have more instances on a single server.
# INSTANCE=$(uname -n)

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a 1GB fixed-size cache file.
#
# DAEMON_OPTS="-a :6081
# -T localhost:6082
# -b localhost:8080
# -u varnish -g varnish
# -S /etc/varnish/secret
# -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"


## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a 1GB
# fixed-size cache file.
#
DAEMON_OPTS="-a :8081
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-s malloc,256m
-p esi_syntax=0x2
-p cli_buffer=16384"


## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
# VARNISH_VCL_CONF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
# VARNISH_LISTEN_PORT=6081
#
# # Telnet admin interface listen address and port
# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
# VARNISH_ADMIN_LISTEN_PORT=6082
#
# # The minimum number of worker threads to start
# VARNISH_MIN_THREADS=1
#
# # The Maximum number of worker threads to start
# VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
# VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
# VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
# VARNISH_STORAGE_SIZE=1G
#
# # File containing administration secret
# VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # Backend storage specification
# VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
# VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT}
# -f ${VARNISH_VCL_CONF}
# -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT}
# -t ${VARNISH_TTL}
# -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT}
# -S ${VARNISH_SECRET_FILE}
# -s ${VARNISH_STORAGE}"
#


## Alternative 4, Do It Yourself
#
# DAEMON_OPTS=""


My /etc/nginx/sites-available/site conf:



server {
listen 80;
server_name royalpets.com.br *.royalpets.com.br;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_buffer_size 8k;
proxy_set_header Host $host;
}
}

server {
listen 80;
server_name acp.royalpets.com.br;
root /var/www/acp;
index index.php index.html index.htm;

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

}
server {
listen 8080;

#server_name royalpets.com.br; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/www/magento;

location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

client_max_body_size 10m;
}


Website header (no X-Varnish showing up):



GET / HTTP/1.1
Host: royalpets.com.br
Accept: image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2,es;q=0.2,gl;q=0.2,pl;q=0.2,ja;q=0.2
Referer: https://www.facebook.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Thu, 07 Aug 2014 17:27:44 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: nginx/1.6.0
Set-Cookie: frontend=uosmrugp8cnti8v0pqo564tbj0; expires=Fri, 08-Aug-2014 17:27:42 GMT; path=/; domain=royalpets.com.br; httponly
Transfer-Encoding: chunked
X-Powered-By: PHP/5.3.10-1ubuntu3.13


No errors on the extension page, horrible site speed (8s+), what am I doing wrong?










share|improve this question














bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Where's that varnish config from?

    – Shane Madden
    Aug 7 '14 at 17:51











  • @ShaneMadden it's generated from the module's backend pressing a button, it asks me to download it and upload to /etc/varnish/.

    – Bruno Dombidau
    Aug 7 '14 at 17:55











  • Hmm, I wish they generated with with decent tabbing :( Let's see what it's doing with the requests, run varnishlog and see what the output is when making one of the slow requests?

    – Shane Madden
    Aug 7 '14 at 17:59











  • Shouldn't Magento connect to nginx and nginx connect to Varnish? It appears above as tho you are directing Magento to Varnish directly; but I may not be interpreting the configs accurately.

    – ericx
    Aug 7 '14 at 17:59











  • @ShaneMadden How am I supposed to do that with 10+ online users? I know it's dumb to test it live but it's all I got.

    – Bruno Dombidau
    Aug 7 '14 at 18:16














1












1








1


1






I would highly appreciate an input on whats going wrong here:



Running Magento on Ubuntu 14.04 x64 + Nginx + Mysql + Php5-FPM



Please double check my steps so maybe you could help me point what's messy:




  • Installed Varnish

  • Installed Magento Tupertine (an extension that makes Varnish work with Magento) from http://www.magentocommerce.com/magento-connect/turpentine-varnish-cache.html


  • Set the required configurations on Magento backend, important info bellow:



    Server List: 127.0.0.1:6082
    Backend Host: 127.0.0.1
    Backend Port: 8081




Varnish is running on 8081 and Nginx on 8080.



My /etc/varnish/default.vcl conf:



C{
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
static pthread_mutex_t lrand_mutex = PTHREAD_MUTEX_INITIALIZER;
void generate_uuid(char* buf) {
pthread_mutex_lock(&lrand_mutex);
long a = lrand48();
long b = lrand48();
long c = lrand48();
long d = lrand48();
pthread_mutex_unlock(&lrand_mutex);
// SID must match this regex for Kount compat /^w{1,32}$/
sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx",
a,
b & 0xffff,
(b & ((long)0x0fff0000) >> 16) | 0x4000,
(c & 0x0fff) | 0x8000,
(c & (long)0xffff0000) >> 16,
d
);
return;
}
}C
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 300s;
.between_bytes_timeout = 300s;
}
backend admin {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 21600s;
.between_bytes_timeout = 21600s;
}
acl crawler_acl {
"127.0.0.1";
}
acl debug_acl {
}
sub generate_session {
if (req.url ~ ".*[&?]SID=([^&]+).*") {
set req.http.X-Varnish-Faked-Session = regsub(
req.url, ".*[&?]SID=([^&]+).*", "frontend=1");
} else {
C{
char uuid_buf [50];
generate_uuid(uuid_buf);
VRT_SetHdr(sp, HDR_REQ,
"30X-Varnish-Faked-Session:",
uuid_buf,
vrt_magic_string_end
);
}C
}
if (req.http.Cookie) {
std.collect(req.http.Cookie);
set req.http.Cookie = req.http.X-Varnish-Faked-Session +
"; " + req.http.Cookie;
} else {
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
}
}
sub generate_session_expires {
C{
time_t now = time(NULL);
struct tm now_tm = *gmtime(&now);
now_tm.tm_sec += 86400;
mktime(&now_tm);
char date_buf [50];
strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm);
VRT_SetHdr(sp, HDR_RESP,
"31X-Varnish-Cookie-Expires:",
date_buf,
vrt_magic_string_end
);
}C
}
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (!false || req.http.Authorization ||
req.request !~ "^(GET|HEAD)$" ||
req.http.Cookie ~ "varnish_bypass=1") {
return (pipe);
}
set req.url = regsuball(req.url, "(.*)//+(.*)", "1/2");
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
set req.http.X-Turpentine-Secret-Handshake = "1";
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?admin") {
set req.backend = admin;
return (pipe);
}
if (req.http.Cookie ~ "bcurrency=") {
set req.http.X-Varnish-Currency = regsub(
req.http.Cookie, ".*bcurrency=([^;]*).*", "1");
}
if (req.http.Cookie ~ "bstore=") {
set req.http.X-Varnish-Store = regsub(
req.http.Cookie, ".*bstore=([^;]*).*", "1");
}
if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") {
set req.http.X-Varnish-Esi-Method = regsub(
req.url, ".*/method/(w+)/.*", "1");
set req.http.X-Varnish-Esi-Access = regsub(
req.url, ".*/access/(w+)/.*", "1");
if (req.http.X-Varnish-Esi-Method == "esi" && req.esi_level == 0 &&
!(false || client.ip ~ debug_acl)) {
error 403 "External ESI requests are not allowed";
}
}
if (req.http.Cookie !~ "frontend=") {
if (client.ip ~ crawler_acl ||
req.http.User-Agent ~ "^(?:ApacheBench/.*|.*Googlebot.*|JoeDog/.*Siege.*|magespeedtest.com|Nexcessnet_Turpentine/.*)$") {
set req.http.Cookie = "frontend=crawler-session";
} else {
call generate_session;
}
}
if (true &&
req.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
unset req.http.Cookie;
unset req.http.X-Varnish-Faked-Session;
return (lookup);
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?(?:admin|api|cron.php)" ||
req.url ~ "?.*__from_store=") {
return (pipe);
}
if (true &&
req.url ~ "(?:[?&](?:__SID|XDEBUG_PROFILE)(?=[&=]|$))") {
return (pass);
}
if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") {
set req.url = regsuball(req.url, "(?:(?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "1");
set req.url = regsuball(req.url, "(?:(?)&|?$)", "1");
}
return (lookup);
}
}
sub vcl_pipe {
unset bereq.http.X-Turpentine-Secret-Handshake;
set bereq.http.Connection = "close";
}
sub vcl_hash {
hash_data(req.url);
if (req.http.Host) {
hash_data(req.http.Host);
} else {
hash_data(server.ip);
}
hash_data(req.http.Ssl-Offloaded);
if (req.http.X-Normalized-User-Agent) {
hash_data(req.http.X-Normalized-User-Agent);
}
if (req.http.Accept-Encoding) {
hash_data(req.http.Accept-Encoding);
}
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
}
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "1"));
}
return (hash);
}
sub vcl_hit {
}
sub vcl_fetch {
set req.grace = 15s;
set beresp.http.X-Varnish-Host = req.http.host;
set beresp.http.X-Varnish-URL = req.url;
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
unset beresp.http.Vary;
set beresp.do_gzip = true;
if (beresp.status != 200 && beresp.status != 404) {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (beresp.http.Set-Cookie) {
set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie;
unset beresp.http.Set-Cookie;
}
unset beresp.http.Cache-Control;
unset beresp.http.Expires;
unset beresp.http.Pragma;
unset beresp.http.Cache;
unset beresp.http.Age;
if (beresp.http.X-Turpentine-Esi == "1") {
set beresp.do_esi = true;
}
if (beresp.http.X-Turpentine-Cache == "0") {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (true &&
bereq.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
set beresp.ttl = 28800s;
set beresp.http.Cache-Control = "max-age=28800";
} elseif (req.http.X-Varnish-Esi-Method) {
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
set beresp.http.X-Varnish-Session = regsub(req.http.Cookie,
"^.*?frontend=([^;]*);*.*$", "1");
}
if (req.http.X-Varnish-Esi-Method == "ajax" &&
req.http.X-Varnish-Esi-Access == "public") {
set beresp.http.Cache-Control = "max-age=" + regsub(
req.url, ".*/ttl/(d+)/.*", "1");
}
set beresp.ttl = std.duration(
regsub(
req.url, ".*/ttl/(d+)/.*", "1s"),
300s);
if (beresp.ttl == 0s) {
set beresp.ttl = 15s;
return (hit_for_pass);
}
} else {
set beresp.ttl = 3600s;
}
}
}
return (deliver);
}
}
sub vcl_deliver {
if (req.http.X-Varnish-Faked-Session) {
call generate_session_expires;
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
if (req.http.Host) {
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + regsub(req.http.Host, ":d+$", "");
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
unset resp.http.X-Varnish-Cookie-Expires;
}
if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") {
set resp.http.Cache-Control = "no-cache";
}
if (true || client.ip ~ debug_acl) {
set resp.http.X-Varnish-Hits = obj.hits;
set resp.http.X-Varnish-Esi-Method = req.http.X-Varnish-Esi-Method;
set resp.http.X-Varnish-Esi-Access = req.http.X-Varnish-Esi-Access;
set resp.http.X-Varnish-Currency = req.http.X-Varnish-Currency;
set resp.http.X-Varnish-Store = req.http.X-Varnish-Store;
} else {
#unset resp.http.X-Varnish;
unset resp.http.Via;
unset resp.http.X-Powered-By;
unset resp.http.Server;
unset resp.http.X-Turpentine-Cache;
unset resp.http.X-Turpentine-Esi;
unset resp.http.X-Turpentine-Flush-Events;
unset resp.http.X-Turpentine-Block;
unset resp.http.X-Varnish-Session;
unset resp.http.X-Varnish-Host;
unset resp.http.X-Varnish-URL;
unset resp.http.X-Varnish-Set-Cookie;
}
}


My /etc/default/varnish conf:



# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#

# Should we start varnishd at boot? Set to "no" to disable.
START=yes

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Maximum locked memory size (for ulimit -l)
# Used for locking the shared memory log in memory. If you increase log size,
# you need to increase this number as well
MEMLOCK=82000

# Default varnish instance name is the local nodename. Can be overridden with
# the -n switch, to have more instances on a single server.
# INSTANCE=$(uname -n)

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a 1GB fixed-size cache file.
#
# DAEMON_OPTS="-a :6081
# -T localhost:6082
# -b localhost:8080
# -u varnish -g varnish
# -S /etc/varnish/secret
# -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"


## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a 1GB
# fixed-size cache file.
#
DAEMON_OPTS="-a :8081
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-s malloc,256m
-p esi_syntax=0x2
-p cli_buffer=16384"


## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
# VARNISH_VCL_CONF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
# VARNISH_LISTEN_PORT=6081
#
# # Telnet admin interface listen address and port
# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
# VARNISH_ADMIN_LISTEN_PORT=6082
#
# # The minimum number of worker threads to start
# VARNISH_MIN_THREADS=1
#
# # The Maximum number of worker threads to start
# VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
# VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
# VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
# VARNISH_STORAGE_SIZE=1G
#
# # File containing administration secret
# VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # Backend storage specification
# VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
# VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT}
# -f ${VARNISH_VCL_CONF}
# -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT}
# -t ${VARNISH_TTL}
# -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT}
# -S ${VARNISH_SECRET_FILE}
# -s ${VARNISH_STORAGE}"
#


## Alternative 4, Do It Yourself
#
# DAEMON_OPTS=""


My /etc/nginx/sites-available/site conf:



server {
listen 80;
server_name royalpets.com.br *.royalpets.com.br;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_buffer_size 8k;
proxy_set_header Host $host;
}
}

server {
listen 80;
server_name acp.royalpets.com.br;
root /var/www/acp;
index index.php index.html index.htm;

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

}
server {
listen 8080;

#server_name royalpets.com.br; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/www/magento;

location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

client_max_body_size 10m;
}


Website header (no X-Varnish showing up):



GET / HTTP/1.1
Host: royalpets.com.br
Accept: image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2,es;q=0.2,gl;q=0.2,pl;q=0.2,ja;q=0.2
Referer: https://www.facebook.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Thu, 07 Aug 2014 17:27:44 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: nginx/1.6.0
Set-Cookie: frontend=uosmrugp8cnti8v0pqo564tbj0; expires=Fri, 08-Aug-2014 17:27:42 GMT; path=/; domain=royalpets.com.br; httponly
Transfer-Encoding: chunked
X-Powered-By: PHP/5.3.10-1ubuntu3.13


No errors on the extension page, horrible site speed (8s+), what am I doing wrong?










share|improve this question














I would highly appreciate an input on whats going wrong here:



Running Magento on Ubuntu 14.04 x64 + Nginx + Mysql + Php5-FPM



Please double check my steps so maybe you could help me point what's messy:




  • Installed Varnish

  • Installed Magento Tupertine (an extension that makes Varnish work with Magento) from http://www.magentocommerce.com/magento-connect/turpentine-varnish-cache.html


  • Set the required configurations on Magento backend, important info bellow:



    Server List: 127.0.0.1:6082
    Backend Host: 127.0.0.1
    Backend Port: 8081




Varnish is running on 8081 and Nginx on 8080.



My /etc/varnish/default.vcl conf:



C{
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
static pthread_mutex_t lrand_mutex = PTHREAD_MUTEX_INITIALIZER;
void generate_uuid(char* buf) {
pthread_mutex_lock(&lrand_mutex);
long a = lrand48();
long b = lrand48();
long c = lrand48();
long d = lrand48();
pthread_mutex_unlock(&lrand_mutex);
// SID must match this regex for Kount compat /^w{1,32}$/
sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx",
a,
b & 0xffff,
(b & ((long)0x0fff0000) >> 16) | 0x4000,
(c & 0x0fff) | 0x8000,
(c & (long)0xffff0000) >> 16,
d
);
return;
}
}C
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 300s;
.between_bytes_timeout = 300s;
}
backend admin {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 21600s;
.between_bytes_timeout = 21600s;
}
acl crawler_acl {
"127.0.0.1";
}
acl debug_acl {
}
sub generate_session {
if (req.url ~ ".*[&?]SID=([^&]+).*") {
set req.http.X-Varnish-Faked-Session = regsub(
req.url, ".*[&?]SID=([^&]+).*", "frontend=1");
} else {
C{
char uuid_buf [50];
generate_uuid(uuid_buf);
VRT_SetHdr(sp, HDR_REQ,
"30X-Varnish-Faked-Session:",
uuid_buf,
vrt_magic_string_end
);
}C
}
if (req.http.Cookie) {
std.collect(req.http.Cookie);
set req.http.Cookie = req.http.X-Varnish-Faked-Session +
"; " + req.http.Cookie;
} else {
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
}
}
sub generate_session_expires {
C{
time_t now = time(NULL);
struct tm now_tm = *gmtime(&now);
now_tm.tm_sec += 86400;
mktime(&now_tm);
char date_buf [50];
strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm);
VRT_SetHdr(sp, HDR_RESP,
"31X-Varnish-Cookie-Expires:",
date_buf,
vrt_magic_string_end
);
}C
}
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (!false || req.http.Authorization ||
req.request !~ "^(GET|HEAD)$" ||
req.http.Cookie ~ "varnish_bypass=1") {
return (pipe);
}
set req.url = regsuball(req.url, "(.*)//+(.*)", "1/2");
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
set req.http.X-Turpentine-Secret-Handshake = "1";
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?admin") {
set req.backend = admin;
return (pipe);
}
if (req.http.Cookie ~ "bcurrency=") {
set req.http.X-Varnish-Currency = regsub(
req.http.Cookie, ".*bcurrency=([^;]*).*", "1");
}
if (req.http.Cookie ~ "bstore=") {
set req.http.X-Varnish-Store = regsub(
req.http.Cookie, ".*bstore=([^;]*).*", "1");
}
if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") {
set req.http.X-Varnish-Esi-Method = regsub(
req.url, ".*/method/(w+)/.*", "1");
set req.http.X-Varnish-Esi-Access = regsub(
req.url, ".*/access/(w+)/.*", "1");
if (req.http.X-Varnish-Esi-Method == "esi" && req.esi_level == 0 &&
!(false || client.ip ~ debug_acl)) {
error 403 "External ESI requests are not allowed";
}
}
if (req.http.Cookie !~ "frontend=") {
if (client.ip ~ crawler_acl ||
req.http.User-Agent ~ "^(?:ApacheBench/.*|.*Googlebot.*|JoeDog/.*Siege.*|magespeedtest.com|Nexcessnet_Turpentine/.*)$") {
set req.http.Cookie = "frontend=crawler-session";
} else {
call generate_session;
}
}
if (true &&
req.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
unset req.http.Cookie;
unset req.http.X-Varnish-Faked-Session;
return (lookup);
}
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?(?:admin|api|cron.php)" ||
req.url ~ "?.*__from_store=") {
return (pipe);
}
if (true &&
req.url ~ "(?:[?&](?:__SID|XDEBUG_PROFILE)(?=[&=]|$))") {
return (pass);
}
if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") {
set req.url = regsuball(req.url, "(?:(?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "1");
set req.url = regsuball(req.url, "(?:(?)&|?$)", "1");
}
return (lookup);
}
}
sub vcl_pipe {
unset bereq.http.X-Turpentine-Secret-Handshake;
set bereq.http.Connection = "close";
}
sub vcl_hash {
hash_data(req.url);
if (req.http.Host) {
hash_data(req.http.Host);
} else {
hash_data(server.ip);
}
hash_data(req.http.Ssl-Offloaded);
if (req.http.X-Normalized-User-Agent) {
hash_data(req.http.X-Normalized-User-Agent);
}
if (req.http.Accept-Encoding) {
hash_data(req.http.Accept-Encoding);
}
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
}
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "1"));
}
return (hash);
}
sub vcl_hit {
}
sub vcl_fetch {
set req.grace = 15s;
set beresp.http.X-Varnish-Host = req.http.host;
set beresp.http.X-Varnish-URL = req.url;
if (req.url ~ "^(/media/|/skin/|/js/|/)(?:(?:index|litespeed).php/)?") {
unset beresp.http.Vary;
set beresp.do_gzip = true;
if (beresp.status != 200 && beresp.status != 404) {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (beresp.http.Set-Cookie) {
set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie;
unset beresp.http.Set-Cookie;
}
unset beresp.http.Cache-Control;
unset beresp.http.Expires;
unset beresp.http.Pragma;
unset beresp.http.Cache;
unset beresp.http.Age;
if (beresp.http.X-Turpentine-Esi == "1") {
set beresp.do_esi = true;
}
if (beresp.http.X-Turpentine-Cache == "0") {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (true &&
bereq.url ~ ".*.(?:css|js|jpe?g|png|gif|ico|swf)(?=?|&|$)") {
set beresp.ttl = 28800s;
set beresp.http.Cache-Control = "max-age=28800";
} elseif (req.http.X-Varnish-Esi-Method) {
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
set beresp.http.X-Varnish-Session = regsub(req.http.Cookie,
"^.*?frontend=([^;]*);*.*$", "1");
}
if (req.http.X-Varnish-Esi-Method == "ajax" &&
req.http.X-Varnish-Esi-Access == "public") {
set beresp.http.Cache-Control = "max-age=" + regsub(
req.url, ".*/ttl/(d+)/.*", "1");
}
set beresp.ttl = std.duration(
regsub(
req.url, ".*/ttl/(d+)/.*", "1s"),
300s);
if (beresp.ttl == 0s) {
set beresp.ttl = 15s;
return (hit_for_pass);
}
} else {
set beresp.ttl = 3600s;
}
}
}
return (deliver);
}
}
sub vcl_deliver {
if (req.http.X-Varnish-Faked-Session) {
call generate_session_expires;
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
if (req.http.Host) {
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + regsub(req.http.Host, ":d+$", "");
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
unset resp.http.X-Varnish-Cookie-Expires;
}
if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") {
set resp.http.Cache-Control = "no-cache";
}
if (true || client.ip ~ debug_acl) {
set resp.http.X-Varnish-Hits = obj.hits;
set resp.http.X-Varnish-Esi-Method = req.http.X-Varnish-Esi-Method;
set resp.http.X-Varnish-Esi-Access = req.http.X-Varnish-Esi-Access;
set resp.http.X-Varnish-Currency = req.http.X-Varnish-Currency;
set resp.http.X-Varnish-Store = req.http.X-Varnish-Store;
} else {
#unset resp.http.X-Varnish;
unset resp.http.Via;
unset resp.http.X-Powered-By;
unset resp.http.Server;
unset resp.http.X-Turpentine-Cache;
unset resp.http.X-Turpentine-Esi;
unset resp.http.X-Turpentine-Flush-Events;
unset resp.http.X-Turpentine-Block;
unset resp.http.X-Varnish-Session;
unset resp.http.X-Varnish-Host;
unset resp.http.X-Varnish-URL;
unset resp.http.X-Varnish-Set-Cookie;
}
}


My /etc/default/varnish conf:



# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#

# Should we start varnishd at boot? Set to "no" to disable.
START=yes

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Maximum locked memory size (for ulimit -l)
# Used for locking the shared memory log in memory. If you increase log size,
# you need to increase this number as well
MEMLOCK=82000

# Default varnish instance name is the local nodename. Can be overridden with
# the -n switch, to have more instances on a single server.
# INSTANCE=$(uname -n)

# This file contains 4 alternatives, please use only one.

## Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# content server on localhost:8080. Use a 1GB fixed-size cache file.
#
# DAEMON_OPTS="-a :6081
# -T localhost:6082
# -b localhost:8080
# -u varnish -g varnish
# -S /etc/varnish/secret
# -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"


## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request. Use a 1GB
# fixed-size cache file.
#
DAEMON_OPTS="-a :8081
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-s malloc,256m
-p esi_syntax=0x2
-p cli_buffer=16384"


## Alternative 3, Advanced configuration
#
# See varnishd(1) for more information.
#
# # Main configuration file. You probably want to change it :)
# VARNISH_VCL_CONF=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
# VARNISH_LISTEN_PORT=6081
#
# # Telnet admin interface listen address and port
# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
# VARNISH_ADMIN_LISTEN_PORT=6082
#
# # The minimum number of worker threads to start
# VARNISH_MIN_THREADS=1
#
# # The Maximum number of worker threads to start
# VARNISH_MAX_THREADS=1000
#
# # Idle timeout for worker threads
# VARNISH_THREAD_TIMEOUT=120
#
# # Cache file location
# VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
#
# # Cache file size: in bytes, optionally using k / M / G / T suffix,
# # or in percentage of available disk space using the % suffix.
# VARNISH_STORAGE_SIZE=1G
#
# # File containing administration secret
# VARNISH_SECRET_FILE=/etc/varnish/secret
#
# # Backend storage specification
# VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
#
# # Default TTL used when the backend does not specify one
# VARNISH_TTL=120
#
# # DAEMON_OPTS is used by the init script. If you add or remove options, make
# # sure you update this section, too.
# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT}
# -f ${VARNISH_VCL_CONF}
# -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT}
# -t ${VARNISH_TTL}
# -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT}
# -S ${VARNISH_SECRET_FILE}
# -s ${VARNISH_STORAGE}"
#


## Alternative 4, Do It Yourself
#
# DAEMON_OPTS=""


My /etc/nginx/sites-available/site conf:



server {
listen 80;
server_name royalpets.com.br *.royalpets.com.br;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_buffer_size 8k;
proxy_set_header Host $host;
}
}

server {
listen 80;
server_name acp.royalpets.com.br;
root /var/www/acp;
index index.php index.html index.htm;

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

}
server {
listen 8080;

#server_name royalpets.com.br; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/www/magento;

location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}

## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}

client_max_body_size 10m;
}


Website header (no X-Varnish showing up):



GET / HTTP/1.1
Host: royalpets.com.br
Accept: image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2,es;q=0.2,gl;q=0.2,pl;q=0.2,ja;q=0.2
Referer: https://www.facebook.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Thu, 07 Aug 2014 17:27:44 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: nginx/1.6.0
Set-Cookie: frontend=uosmrugp8cnti8v0pqo564tbj0; expires=Fri, 08-Aug-2014 17:27:42 GMT; path=/; domain=royalpets.com.br; httponly
Transfer-Encoding: chunked
X-Powered-By: PHP/5.3.10-1ubuntu3.13


No errors on the extension page, horrible site speed (8s+), what am I doing wrong?







varnish cache magento






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 7 '14 at 17:49









Bruno DombidauBruno Dombidau

613




613





bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Where's that varnish config from?

    – Shane Madden
    Aug 7 '14 at 17:51











  • @ShaneMadden it's generated from the module's backend pressing a button, it asks me to download it and upload to /etc/varnish/.

    – Bruno Dombidau
    Aug 7 '14 at 17:55











  • Hmm, I wish they generated with with decent tabbing :( Let's see what it's doing with the requests, run varnishlog and see what the output is when making one of the slow requests?

    – Shane Madden
    Aug 7 '14 at 17:59











  • Shouldn't Magento connect to nginx and nginx connect to Varnish? It appears above as tho you are directing Magento to Varnish directly; but I may not be interpreting the configs accurately.

    – ericx
    Aug 7 '14 at 17:59











  • @ShaneMadden How am I supposed to do that with 10+ online users? I know it's dumb to test it live but it's all I got.

    – Bruno Dombidau
    Aug 7 '14 at 18:16



















  • Where's that varnish config from?

    – Shane Madden
    Aug 7 '14 at 17:51











  • @ShaneMadden it's generated from the module's backend pressing a button, it asks me to download it and upload to /etc/varnish/.

    – Bruno Dombidau
    Aug 7 '14 at 17:55











  • Hmm, I wish they generated with with decent tabbing :( Let's see what it's doing with the requests, run varnishlog and see what the output is when making one of the slow requests?

    – Shane Madden
    Aug 7 '14 at 17:59











  • Shouldn't Magento connect to nginx and nginx connect to Varnish? It appears above as tho you are directing Magento to Varnish directly; but I may not be interpreting the configs accurately.

    – ericx
    Aug 7 '14 at 17:59











  • @ShaneMadden How am I supposed to do that with 10+ online users? I know it's dumb to test it live but it's all I got.

    – Bruno Dombidau
    Aug 7 '14 at 18:16

















Where's that varnish config from?

– Shane Madden
Aug 7 '14 at 17:51





Where's that varnish config from?

– Shane Madden
Aug 7 '14 at 17:51













@ShaneMadden it's generated from the module's backend pressing a button, it asks me to download it and upload to /etc/varnish/.

– Bruno Dombidau
Aug 7 '14 at 17:55





@ShaneMadden it's generated from the module's backend pressing a button, it asks me to download it and upload to /etc/varnish/.

– Bruno Dombidau
Aug 7 '14 at 17:55













Hmm, I wish they generated with with decent tabbing :( Let's see what it's doing with the requests, run varnishlog and see what the output is when making one of the slow requests?

– Shane Madden
Aug 7 '14 at 17:59





Hmm, I wish they generated with with decent tabbing :( Let's see what it's doing with the requests, run varnishlog and see what the output is when making one of the slow requests?

– Shane Madden
Aug 7 '14 at 17:59













Shouldn't Magento connect to nginx and nginx connect to Varnish? It appears above as tho you are directing Magento to Varnish directly; but I may not be interpreting the configs accurately.

– ericx
Aug 7 '14 at 17:59





Shouldn't Magento connect to nginx and nginx connect to Varnish? It appears above as tho you are directing Magento to Varnish directly; but I may not be interpreting the configs accurately.

– ericx
Aug 7 '14 at 17:59













@ShaneMadden How am I supposed to do that with 10+ online users? I know it's dumb to test it live but it's all I got.

– Bruno Dombidau
Aug 7 '14 at 18:16





@ShaneMadden How am I supposed to do that with 10+ online users? I know it's dumb to test it live but it's all I got.

– Bruno Dombidau
Aug 7 '14 at 18:16










3 Answers
3






active

oldest

votes


















0














The way I have setup Varnish/Magento with Turpentine before is like this:



Have varnish listen on port 80, nginx on any port (something like 8080)



Configure varnish to listen on port 80 in /etc/default/varnish.conf



Configure /etc/varnish/default.vcl and set backend to 8080 (which is set right now)



so the requests from internet will hit on Varnish and if it finds the static content in it's cache it won't go back to the nginx to process. It will simply deliver that content from it's cache.



The cache is set to store in RAM as it's set to malloc 256m means 256MB in RAM
you can also store it's cache in Hard Disk in a file and size it according to your disk space and needs.



nginx does not need to listen on port 80 because you will have Varnish there. So any request which is not served by Varnish will be sent back to nginx on port 8080. Nginx will send that back to php-fpm which will process it and send back the results to nginx which in turn will send the results to Varnish which again sends it to browser.



the headers are set in the varnish vcl file. You may see the varnish headers once it's listening on port 80 and delivering the content to browsers.






share|improve this answer
























  • That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

    – Bruno Dombidau
    Aug 8 '14 at 17:18



















0














Try to disable full page cache in Magento go to System->Configuration->Advanced->System and External Full Page Cache Settings. After that flush External page cache in Cache Storage Management.



If still will not work try to disable in Cache Storage Management-> Blocks HTML output



Also Varnish cache needs warm up so try enable Settings->turpentine->Varnish Options->Enable Site Crawler check later in nginx logs if crawler is accessing website






share|improve this answer































    0














    Why install an additional cache when the server you have already has one integrated?



    I am not using Magento but similar to Wordpress I am sure it uses many cookies. Varnish will strip all of those unless you tell it to. From my experience you should disable Varnish and enable the Nginx cache to avoid many headaches.



    proxy_buffer on;


    Make sure to configure the proxy cache size:



    proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:300m inactive=24h max_size=1G;


    Also make sure to configure it



    proxy_cache_valid 200 30m;


    Lower to 15m if you have problems with pageviews/user or stale caching.



     expires 30m;


    Those are the values I have tested for some time on a production server. Try them and see if the Nginx cache is performing better than your Varnish cache. In my case it performed way better and is easier to maintain. I will never touch Varnish again. Too hard to maintain.






    share|improve this answer
























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "2"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f618787%2fvarnish-doesnt-seems-to-be-doing-anything%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The way I have setup Varnish/Magento with Turpentine before is like this:



      Have varnish listen on port 80, nginx on any port (something like 8080)



      Configure varnish to listen on port 80 in /etc/default/varnish.conf



      Configure /etc/varnish/default.vcl and set backend to 8080 (which is set right now)



      so the requests from internet will hit on Varnish and if it finds the static content in it's cache it won't go back to the nginx to process. It will simply deliver that content from it's cache.



      The cache is set to store in RAM as it's set to malloc 256m means 256MB in RAM
      you can also store it's cache in Hard Disk in a file and size it according to your disk space and needs.



      nginx does not need to listen on port 80 because you will have Varnish there. So any request which is not served by Varnish will be sent back to nginx on port 8080. Nginx will send that back to php-fpm which will process it and send back the results to nginx which in turn will send the results to Varnish which again sends it to browser.



      the headers are set in the varnish vcl file. You may see the varnish headers once it's listening on port 80 and delivering the content to browsers.






      share|improve this answer
























      • That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

        – Bruno Dombidau
        Aug 8 '14 at 17:18
















      0














      The way I have setup Varnish/Magento with Turpentine before is like this:



      Have varnish listen on port 80, nginx on any port (something like 8080)



      Configure varnish to listen on port 80 in /etc/default/varnish.conf



      Configure /etc/varnish/default.vcl and set backend to 8080 (which is set right now)



      so the requests from internet will hit on Varnish and if it finds the static content in it's cache it won't go back to the nginx to process. It will simply deliver that content from it's cache.



      The cache is set to store in RAM as it's set to malloc 256m means 256MB in RAM
      you can also store it's cache in Hard Disk in a file and size it according to your disk space and needs.



      nginx does not need to listen on port 80 because you will have Varnish there. So any request which is not served by Varnish will be sent back to nginx on port 8080. Nginx will send that back to php-fpm which will process it and send back the results to nginx which in turn will send the results to Varnish which again sends it to browser.



      the headers are set in the varnish vcl file. You may see the varnish headers once it's listening on port 80 and delivering the content to browsers.






      share|improve this answer
























      • That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

        – Bruno Dombidau
        Aug 8 '14 at 17:18














      0












      0








      0







      The way I have setup Varnish/Magento with Turpentine before is like this:



      Have varnish listen on port 80, nginx on any port (something like 8080)



      Configure varnish to listen on port 80 in /etc/default/varnish.conf



      Configure /etc/varnish/default.vcl and set backend to 8080 (which is set right now)



      so the requests from internet will hit on Varnish and if it finds the static content in it's cache it won't go back to the nginx to process. It will simply deliver that content from it's cache.



      The cache is set to store in RAM as it's set to malloc 256m means 256MB in RAM
      you can also store it's cache in Hard Disk in a file and size it according to your disk space and needs.



      nginx does not need to listen on port 80 because you will have Varnish there. So any request which is not served by Varnish will be sent back to nginx on port 8080. Nginx will send that back to php-fpm which will process it and send back the results to nginx which in turn will send the results to Varnish which again sends it to browser.



      the headers are set in the varnish vcl file. You may see the varnish headers once it's listening on port 80 and delivering the content to browsers.






      share|improve this answer













      The way I have setup Varnish/Magento with Turpentine before is like this:



      Have varnish listen on port 80, nginx on any port (something like 8080)



      Configure varnish to listen on port 80 in /etc/default/varnish.conf



      Configure /etc/varnish/default.vcl and set backend to 8080 (which is set right now)



      so the requests from internet will hit on Varnish and if it finds the static content in it's cache it won't go back to the nginx to process. It will simply deliver that content from it's cache.



      The cache is set to store in RAM as it's set to malloc 256m means 256MB in RAM
      you can also store it's cache in Hard Disk in a file and size it according to your disk space and needs.



      nginx does not need to listen on port 80 because you will have Varnish there. So any request which is not served by Varnish will be sent back to nginx on port 8080. Nginx will send that back to php-fpm which will process it and send back the results to nginx which in turn will send the results to Varnish which again sends it to browser.



      the headers are set in the varnish vcl file. You may see the varnish headers once it's listening on port 80 and delivering the content to browsers.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 7 '14 at 20:27









      sandeep.s85sandeep.s85

      1,36911226




      1,36911226













      • That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

        – Bruno Dombidau
        Aug 8 '14 at 17:18



















      • That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

        – Bruno Dombidau
        Aug 8 '14 at 17:18

















      That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

      – Bruno Dombidau
      Aug 8 '14 at 17:18





      That's exactly how's it running right now, but Varnish is on 8081 instead of 80 and nginx on 8080.

      – Bruno Dombidau
      Aug 8 '14 at 17:18













      0














      Try to disable full page cache in Magento go to System->Configuration->Advanced->System and External Full Page Cache Settings. After that flush External page cache in Cache Storage Management.



      If still will not work try to disable in Cache Storage Management-> Blocks HTML output



      Also Varnish cache needs warm up so try enable Settings->turpentine->Varnish Options->Enable Site Crawler check later in nginx logs if crawler is accessing website






      share|improve this answer




























        0














        Try to disable full page cache in Magento go to System->Configuration->Advanced->System and External Full Page Cache Settings. After that flush External page cache in Cache Storage Management.



        If still will not work try to disable in Cache Storage Management-> Blocks HTML output



        Also Varnish cache needs warm up so try enable Settings->turpentine->Varnish Options->Enable Site Crawler check later in nginx logs if crawler is accessing website






        share|improve this answer


























          0












          0








          0







          Try to disable full page cache in Magento go to System->Configuration->Advanced->System and External Full Page Cache Settings. After that flush External page cache in Cache Storage Management.



          If still will not work try to disable in Cache Storage Management-> Blocks HTML output



          Also Varnish cache needs warm up so try enable Settings->turpentine->Varnish Options->Enable Site Crawler check later in nginx logs if crawler is accessing website






          share|improve this answer













          Try to disable full page cache in Magento go to System->Configuration->Advanced->System and External Full Page Cache Settings. After that flush External page cache in Cache Storage Management.



          If still will not work try to disable in Cache Storage Management-> Blocks HTML output



          Also Varnish cache needs warm up so try enable Settings->turpentine->Varnish Options->Enable Site Crawler check later in nginx logs if crawler is accessing website







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 13 '14 at 5:22









          Markus07Markus07

          1




          1























              0














              Why install an additional cache when the server you have already has one integrated?



              I am not using Magento but similar to Wordpress I am sure it uses many cookies. Varnish will strip all of those unless you tell it to. From my experience you should disable Varnish and enable the Nginx cache to avoid many headaches.



              proxy_buffer on;


              Make sure to configure the proxy cache size:



              proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:300m inactive=24h max_size=1G;


              Also make sure to configure it



              proxy_cache_valid 200 30m;


              Lower to 15m if you have problems with pageviews/user or stale caching.



               expires 30m;


              Those are the values I have tested for some time on a production server. Try them and see if the Nginx cache is performing better than your Varnish cache. In my case it performed way better and is easier to maintain. I will never touch Varnish again. Too hard to maintain.






              share|improve this answer




























                0














                Why install an additional cache when the server you have already has one integrated?



                I am not using Magento but similar to Wordpress I am sure it uses many cookies. Varnish will strip all of those unless you tell it to. From my experience you should disable Varnish and enable the Nginx cache to avoid many headaches.



                proxy_buffer on;


                Make sure to configure the proxy cache size:



                proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:300m inactive=24h max_size=1G;


                Also make sure to configure it



                proxy_cache_valid 200 30m;


                Lower to 15m if you have problems with pageviews/user or stale caching.



                 expires 30m;


                Those are the values I have tested for some time on a production server. Try them and see if the Nginx cache is performing better than your Varnish cache. In my case it performed way better and is easier to maintain. I will never touch Varnish again. Too hard to maintain.






                share|improve this answer


























                  0












                  0








                  0







                  Why install an additional cache when the server you have already has one integrated?



                  I am not using Magento but similar to Wordpress I am sure it uses many cookies. Varnish will strip all of those unless you tell it to. From my experience you should disable Varnish and enable the Nginx cache to avoid many headaches.



                  proxy_buffer on;


                  Make sure to configure the proxy cache size:



                  proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:300m inactive=24h max_size=1G;


                  Also make sure to configure it



                  proxy_cache_valid 200 30m;


                  Lower to 15m if you have problems with pageviews/user or stale caching.



                   expires 30m;


                  Those are the values I have tested for some time on a production server. Try them and see if the Nginx cache is performing better than your Varnish cache. In my case it performed way better and is easier to maintain. I will never touch Varnish again. Too hard to maintain.






                  share|improve this answer













                  Why install an additional cache when the server you have already has one integrated?



                  I am not using Magento but similar to Wordpress I am sure it uses many cookies. Varnish will strip all of those unless you tell it to. From my experience you should disable Varnish and enable the Nginx cache to avoid many headaches.



                  proxy_buffer on;


                  Make sure to configure the proxy cache size:



                  proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:300m inactive=24h max_size=1G;


                  Also make sure to configure it



                  proxy_cache_valid 200 30m;


                  Lower to 15m if you have problems with pageviews/user or stale caching.



                   expires 30m;


                  Those are the values I have tested for some time on a production server. Try them and see if the Nginx cache is performing better than your Varnish cache. In my case it performed way better and is easier to maintain. I will never touch Varnish again. Too hard to maintain.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 16 '15 at 10:03









                  mashupmashup

                  15511




                  15511






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Server Fault!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f618787%2fvarnish-doesnt-seems-to-be-doing-anything%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      117736 Шеррод Примітки | Див. також | Посилання | Навігаційне...

                      As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

                      Маріан Котлеба Зміст Життєпис | Політичні погляди |...