nginx

WordPress nocache_headers() vs. Nginx

Typically, you can call WordPress’ nocache_headers() function when you don’t want content to be cached. Typically, but when you’re serving from behind Nginx as a reverse proxy, consideration must be paid.

It’s a year old now, so I shouldn’t have been surprised by it, but this thread on the Nginx forums explains that Cache-Control: private headers are meaningless when Nginx is being used as a reverse proxy:

nginx completely ignores the ‘private’ keyword and will cache your document regardless.

The recommendation is for the upstream app to send an X-Accel-Expires: 0 header.

The easy fix? Add a filter to nocache_headers() that inserts the additional header:

add_action( 'nocache_headers' , 'my_nocache_headers' , 1 );
function my_nocache_headers( $headers )
{
	$headers['X-Accel-Expires'] = 0;
	return $headers;
}

Chris Lea On Nginx And WordPress

“Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.” —Chris Lea.

Why? No forking. No loading of unnecessary components. Fast CGI. And to prove it’s not as complex as you might think, he’s installing it live. The session has eight minutes left, can he do it?

Yes, he did. The big concern is in managing permalinks without .htaccess, and it turns out it’s not so difficult. Does he have a cookbook for this? Darn, no time left for questions, I’ll have to ask later.