I am specifically using the email automation software Mautic. Mautic has a JS tracking code that is dynamically generated (/mtc.js
), but the generation isn't cached. I'm using nginx as my webserver.
The logical thing to do here is to use fastcgi_cache to cache the outputs of the file. How can I use fastcgi_cache to cache a the JS file that is generated by PHP? Is there a better alternative?
Here are the relevant parts of my vhost (excluding Cerbot stuff):
fastcgi_cache_path /var/www/mail.zachrussell.net/cache levels=1:2 keys_zone=mail.zachrussell.net:100m inactive=60m;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
server {
server_name mail.zachrussell.net www.mail.zachrussell.net;
access_log /var/www/mail.zachrussell.net/logs/access.log;
error_log /var/www/mail.zachrussell.net/logs/error.log;
root /var/www/mail.zachrussell.net/public;
index index.php;
set $skip_cache 0;
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
#set $skip_cache 1;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache mail.zachrussell.net;
fastcgi_cache_valid 60m;
}
[... certbot stuff ...]
}