My site sits on a server that uses Varnish as a (powerful) caching engine.
Unfortunately, it seems wordpress is busting the Varnish cache by sending a cache-control http header. If I curl -I domain.com
I get:
HTTP/1.1 200 OK
Server: Apache/2.4.10
X-Powered-By: PHP/5.4.4-14+deb7u14
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=e00738aoughg407ljm270kj0l6; path=/
Content-Type: text/html; charset=UTF-8
Accept-Ranges: bytes
Date: Fri, 31 Oct 2014 21:44:16 GMT
Connection: keep-alive
Via: 1.1 varnish
Age: 0
I have other wordpress sites hosted on this server, which work correctly with the Varnish server, so I’m pretty sure the problem is caused by this specific installation. Here is what I tried:
- disable all plugins. Empty Varnish cache, then
curl -I
: same result. - looked through all my theme files. Nothing suspicious.
Do you have any other idea as to what may cause the problem?
2 s
Thanks to @chrisguitarguy’s answer, you can control the http headers sent by WordPress via the “send_headers” hook. Here is the function I added to my theme’s functions.php file, and that solved the issue with the Varnish server.
function varnish_safe_http_headers() {
header( 'X-UA-Compatible: IE=edge,chrome=1' );
session_cache_limiter('');
header("Cache-Control: public, s-maxage=120");
if( !session_id() )
{
session_start();
}
}
add_action( 'send_headers', 'varnish_safe_http_headers' );