Commit 5ff1ecf6 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Tweak HTTP caching headers

parent 82dbba4d
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ server {
	set_real_ip_from fd00::/8;
	real_ip_header X-Forwarded-For;

	# Add Cache-Control headers for static files, removed in *.php location
	add_header Cache-Control "public, max-age=7776000, stale-while-revalidate=86400, stale-if-error=604800";

	location ~ \.php$ {
		include fastcgi_params;
		fastcgi_param SCRIPT_FILENAME /app$fastcgi_script_name;
@@ -28,6 +31,7 @@ server {
		fastcgi_param HTTPS $forwarded_https;
		fastcgi_param SERVER_ADDR $http_x_forwarded_host;
		fastcgi_param SERVER_PORT $http_x_forwarded_port;
		add_header X-Clacks-Overhead "GNU Terry Pratchett";
		fastcgi_pass fastcgi;
	}

@@ -43,19 +47,13 @@ server {

	# allow the new JSON REST API
	location /wp-json/ {
		try_files /non-existant /index.php$is_args$args;
		rewrite ^ /index.php$is_args$args last;
	}

	# use /index.php as a front controller if the base of the URI path does
	# not exist
	location / {
		try_files $uri /index.php$is_args$args;
		add_header Cache-Control "public, max-age=7776000, stale-while-revalidate=86400, stale-if-error=604800";
	}

	# serve only static files from wp-includes
	location ^~ /wp-includes/ {
		add_header Cache-Control "public, max-age=7776000, stale-while-revalidate=86400, stale-if-error=604800";
	}

	# wp-admin uses lots of directly accessed PHP scripts, unfortunately
@@ -64,13 +62,18 @@ server {
	}
	location /wp-admin/ {
		try_files $uri $uri/index.php;
		add_header Cache-Control "public, max-age=7776000, stale-while-revalidate=86400, stale-if-error=604800";
	}

	# serve only static files from wp-includes
	location ^~ /wp-includes/ {
		# don't serve PHP source code from wp-includes
		location ~ \.php {
			return 404;
		}
	}

	# serve only static files from wp-content
	location ^~ /wp-content/ {
		add_header Cache-Control "public, max-age=7776000, stale-while-revalidate=86400, stale-if-error=604800";

		# don't serve PHP source code from plugins, etc
		location ~ \.php {
			return 404;