• The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Nginx FastCGI microcaching

Émerson Felinto

Regular Pleskian
Enable Nginx FastCGI microcaching

I really need to enable this feature for my clients. I tried to do it manually but nothing I did worked out, I also do not know how to tell if microcaching is actually active on my site.
There are already questions in the forum related to this, but nobody gave a solution that works to activate microcaching in Plesk, someone who has already managed to install and configure has some solution?
 
Interesting question. Here is an attempt to provide support - no guarantee on this, though. I did not test it and have not done it before.

You need to put these commands before and into the "server" brackets of /etc/nginx/plesk.conf.d/server.conf like this:
Code:
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m;
server {
   proxy_cache cache;
   proxy_cache_valid 200 1s;
   # ...
}
and restart Nginx aftwards. (Example taken from Nginx documentation).

However, the /etc/nginx/plesk.conf.d/server.conf is auto-generated by Plesk. It is probably necessary to create a user template for this file to have these global changes applied to Nginx. The default configuration template for this should be /usr/local/psa/admin/conf/templates/default/nginx.php. The default should NOT be modified. Instead, copy the default to /usr/local/psa/admin/conf/templates/custom/ (the "custom" directory needs to be created for that if it does not yet exist) and edit the custom version of nginx.php there. Now after your custom nginx.php including the special microcaching directives exists, run
# /usr/local/psa/admin/sbin/httpdmng --reconfigure-all
to have Plesk rebuild all configuration files. (I am not aware that it is possible to limit the rebuild process to only the Nginx global files.)
 
I did everything as described, but it just is not working. Is there any way to know Microcaching Nginx is active? I put it to the server to report in the HTTP headers, but it just does not seem to work:

-rw-r--r-- 1 root root 1952 Oct 18 02:08 /usr/local/psa/admin/conf/templates/custom/nginx.php

<?php echo AUTOGENERATED_CONFIGS; ?>

<?php /** @var Template_VariableAccessor $VAR */ ?>
<?php /** @var Template_Variable_IpAddress $ipAddress */ ?>

include "<?php echo $VAR->server->nginx->httpConfDir ?>/plesk.conf.d/ip_default/*.conf";

<?php echo $VAR->includeTemplate('server/nginxVhosts.php', array(
'ssl' => false,
'frontendPort' => $VAR->server->nginx->httpPort,
'backendPort' => $VAR->server->webserver->httpPort,
)) ?>

<?php echo $VAR->includeTemplate('server/nginxVhosts.php', array(
'ssl' => true,
'frontendPort' => $VAR->server->nginx->httpsPort,
'backendPort' => $VAR->server->webserver->httpsPort,
)) ?>

<?php /* Next block used for watchdog */ ?>
<?php if (!$VAR->server->ipAddresses->hasIpV4Address): ?>
server {
listen 127.0.0.1 default_server;
return 200;
}
server {
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_cache_path /tmp/cache levels=1:2 keys_zone=thelastcicada:900m inactive=10m max_size=100m;
fastcgi_cache_key "$scheme://$host$request_method$request_uri";

#Cache everything by default
set $no_cache 0;

#Don't cache logged in users or commenters
if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $no_cache 1;
}

#Don't cache the following URLs
if ($request_uri ~* "/(wp-admin/|wp-login.php)")
{
set $no_cache 1;
}

#matches keys_zone in fastcgi_cache_path
fastcgi_cache thelastcicada;

#don't serve pages defined earlier
fastcgi_cache_bypass $no_cache;

#don't cache pages defined earlier
fastcgi_no_cache $no_cache;

#defines the default cache time
fastcgi_cache_valid any 10s;

#unsure what the impacts of this variable is
fastcgi_max_temp_file_size 2M;

#Use stale cache items while updating in the background
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_cache_lock on;
fastcgi_cache_lock_timeout 10s;

fastcgi_cache_key “$scheme://$host$request_method$request_uri”;
}
<?php endif ?>
 
Back
Top