Add missing headers to FastCGI Microcaching

A while ago I setup FastCGI Microcaching for this website at https://kittmedia.com to improve the page load time dramatically. Now, a while later, I noticed that some HTTP headers are missing in the server responses even if they were added in the configuration. Even after a Google search I couldn’t find any explanation but noticed that the X-Cache header I added for indicating if the microcache hits was added successfully.

I’ve added this header directly inside my FastCGI configuration and so I tried to add the other headers there as well. Et voilà, after adding the other headers to my FastCGI configuration as well, they were also sent to the client now.

So if you ever wonder where the headers go: FastCGI Microcaching seems to ignore any other headers except those directly set inside the location you’ve set the microcache, which usually is the FastCGI configuration for obvious reason.

Fortunately, my headers are separated in individual files by their purpose and thus I could just use additional include commands in my configuration like so:

[…] fastcgi_cache kittmedia; fastcgi_cache_valid 200 60m; fastcgi_cache_bypass $no_cache; fastcgi_no_cache $no_cache; fastcgi_cache_use_stale updating error timeout invalid_header http_500; fastcgi_cache_lock on; fastcgi_cache_lock_timeout 10s; add_header X-Cache $upstream_cache_status; include /etc/nginx/security/default_params; include /etc/nginx/security/csp-kittmedia; […]
Code language: Nginx (nginx)

Leave a Reply

Your email address will not be published. Required fields are marked *