Found this while searching for a solution. I fixed it by moving this line to the top of the vhost file:
fastcgi_ignore_headers X-Accel-Expires Expires Cache-Control;
After this all my requests are properly cached and my site loads really fast! My entire vhost file:
fastcgi_cache_path /etc/nginx-cache levels=1:2 keys_zone=phpcache:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_ignore_headers X-Accel-Expires Expires Cache-Control;
server {
listen 80;
charset utf8;
root /home/user/htdocs/public;
index index.php;
server_name domain.com;
set $no_cache 0;
# Don't cache the CMS admin area
location /admin {
set $no_cache 1;
}
gzip on;
gzip_min_length 10;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml application/x-javascript text/css image/svg+xml;
gzip_vary on;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/domain-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_cache phpcache; # The name of the cache key-zone to use
fastcgi_cache_valid 200 30m; # What to cache: 'code 200' responses, for half an hour
fastcgi_cache_methods GET HEAD; # What to cache: only GET and HEAD requests (ot POST)
add_header X-Fastcgi-Cache $upstream_cache_status; # Allow us to see if the cache was HIT, MISS, or BYPASSED inside a browser's Inspector panel
fastcgi_cache_bypass $no_cache; # Dont pull from the cache if true
fastcgi_no_cache $no_cache; # Dont save to the cache if true
}
location ~ ^(.*)$ {
try_files $uri $uri/ /index.php?p=$uri&$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|ttf|svg)(\?ver=[0-9.]+)?$ { expires 1w; }
location ~ /\.ht {
deny all;
return 404;
}
}
fastcgi_hide_header Set-Cookiewill work. – RitterKnight Oct 09 '15 at 18:09fastcgi_hide_header Set-Cookiewhich does exactly what I need. The problem is, I can't seem to figure out how to do it conditionally. For example, we don't want to strip theSet-Cookieheaders if we aren't serving it up from the cache (otherwise things like the AdminCP can't set their session cookies). Any thoughts? – andrew.welch Jan 05 '17 at 00:23index.phpfile and name it whatever you want, likeindexadmin.php. Make a location block that corresponds to the cp trigger and point requests at that file for backend and front end requests at the regular craft index.php. A slightly cleaner way that works within an if block or location block is the 3rd partymore_clear_headersmodule. If you use ubuntu/debian it's bundled with some PPAs of nginx (the nginx-extras package iirc). – RitterKnight Jan 05 '17 at 14:22