Varnish works perfect if you change the header to header('Cache-Control: public, max-age=10');
.
But Magento overwrites the header with it own header: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, s-maxage=86400
Resulting in never cached pages. But you also don't want Varnish to cache logged in users... So how should I configure Varnish and/or Magento to cache what is necessary to cache?
Varnish 4.0 (4.0.3-1)
PHP 5.6 (5.6.24-1)
Nginx 1.0.15 (1.0.15-12)
Magento 1.9 (1.9.2.4)
Here is my HTTP header:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 08 Aug 2016 08:46:28 GMT
Content-Type: text/html; charset=UTF-8
X-Powered-By: PHP/5.6.24
X-Frame-Options: SAMEORIGIN
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, s-maxage=86400
Expires: Mon, 31 Mar 2008 10:00:00 GMT
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
X-Varnish: 32770
Age: 0
Via: 1.1 varnish-v4
Content-Length: 0
Connection: keep-alive
My Varnish vcl configuration:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
unset req.http.cookie;
}
sub vcl_backend_response {
unset beresp.http.set-cookie;
}
sub vcl_deliver {
unset resp.http.set-cookie;
}
My "nginx.conf" configuration
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
fastcgi_read_timeout 300;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
}
My "default.conf" configuration:
server {
listen 127.0.0.1:8080;
server_name <my website, www.example.com>;
#charset koi8-r;
#access_log logs/host.access.log main;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /var/www/public_html;
index index.php index.html index.htm;
try_files $uri $uri/ @handler;
}
## 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
# root /var/www/public_html;
# expires off; ## Do not cache dynamic content
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# 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
# }
location ~ ^(.+\.php)(.*)$ {
root /var/www/public_html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/public_html/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root /var/www/public_html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}